Allocate N elements

bearophile bearophileHUGS at lycos.com
Mon Jul 15 08:54:56 PDT 2013


monarch_dodra:

>> But that (of new arrays) is a bad design, it wastes too much 
>> memory, and I think it should be fixed. In Python this doesn't 
>> overallocate:
>
> So what? The only thing you showed, is that 
> minimallyInitialized doesn't know how much it allocated. If you 
> allocate 513 elements with malloc, you'll way over allocate 
> too. What's your point?
> You'll waste memory either way.

I didn't know it, sorry. I forgot.
Can we let minimallyInitializedArray know the capacity?

Regarding the small arrays, so to avoid the memory wasting you 
need to allocate a larger one and slice it.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list