Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

size and length

37 views
Skip to first unread message

fir

unread,
May 21, 2022, 7:39:30 AM5/21/22
to
writing dynamic arys i noticed one thing (not even noticed but like
bumped my head on it):

imo the size is probably appriopriate name for axemple on this
what realloc takes this is teh size of ram allocked (for example 1 MB)
-when to know length of such array you need to know the size of
its basic element, for example if this is array of ints the length would
be 256*1024

im not sure if this division of those two separate meanings is official
in computer science, doeas maybe some knows something on it?

Malcolm McLean

unread,
May 22, 2022, 8:17:26 PM5/22/22
to
A lot of languages don't make it easy to determine the number of bytes
used by an array. So there's no convention that "size" represents a
number of bytes whilst "length" represents a number of elements.

If would make sense for C, but the C++ standard template library uses
"szie" for a count, so that ship has sailed.

olcott

unread,
May 23, 2022, 11:13:26 AM5/23/22
to
std::vector<int> array;
int bytes = sizeof(int) * array.size();
That makes the most sense to me.

--
Copyright 2022 Pete Olcott

"Talent hits a target no one else can hit;
Genius hits a target no one else can see."
Arthur Schopenhauer

fir

unread,
May 23, 2022, 11:16:06 AM5/23/22
to
i wouldnt say it sailed .. but if there us as you say it may mean people dont notice
the difference and this difference possibly should be noticed more wide

fir

unread,
May 23, 2022, 11:18:47 AM5/23/22
to
poniedziałek, 23 maja 2022 o 17:13:26 UTC+2 olcott napisał(a):
> On 5/22/2022 7:17 PM, Malcolm McLean wrote:
> > On Saturday, 21 May 2022 at 12:39:30 UTC+1, fir wrote:
> >> writing dynamic arys i noticed one thing (not even noticed but like
> >> bumped my head on it):
> >>
> >> imo the size is probably appriopriate name for axemple on this
> >> what realloc takes this is teh size of ram allocked (for example 1 MB)
> >> -when to know length of such array you need to know the size of
> >> its basic element, for example if this is array of ints the length would
> >> be 256*1024
> >>
> >> im not sure if this division of those two separate meanings is official
> >> in computer science, doeas maybe some knows something on it?
> >>
> > A lot of languages don't make it easy to determine the number of bytes
> > used by an array. So there's no convention that "size" represents a
> > number of bytes whilst "length" represents a number of elements.
> >
> > If would make sense for C, but the C++ standard template library uses
> > "szie" for a count, so that ship has sailed.
> std::vector<int> array;
> int bytes = sizeof(int) * array.size();
> That makes the most sense to me.
>
for me its nonsense (in te context said) should be > int bytes = sizeof(array[0]) * array.length();
0 new messages