Strict capacity of array

Marco Leise Marco.Leise at gmx.de
Fri Dec 13 16:12:40 PST 2013


Am Fri, 13 Dec 2013 21:02:58 +0100
schrieb "FreeSlave" <freeslave93 at gmail.com>:

> Thanks for answers.
> 
> On Friday, 13 December 2013 at 19:35:01 UTC, Marco Leise wrote:
> > Have you tried this?:
> >
> > import core.memory;
> > int[] data = (cast(int*)GC.malloc(size * int.sizeof, 
> > GC.BlkAttr.NO_SCAN))[0 .. size];
> 
> Did you mean GC.BlkAttr.NONE maybe? If I get it right 
> GC.BlkAttr.NO_SCAN means that memory will never be collected by 
> GC (i.e. it's just like C malloc), but I've asked for opposite.

You got it wrong :)
NO_SCAN means that the memory block you allocate isn't
scanned for _more_ references to stuff on the GC heap.
If you use the allocated memory as an int[] it doesn't make
sense to look into it for pointers to other memory blocks in
order to mark them alive. (The GC is a mark&sweep algorithm.)
If you actually store class pointers or similar instead of ints
then drop that attribute.

-- 
Marco



More information about the Digitalmars-d-learn mailing list