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();