On 30 April 2012 01:24, Tove <tove@fransson.se> wrote:
On Sunday, 29 April 2012 at 22:13:22 UTC, Manu wrote:
Is it technically possible to have a precise GC clean up all unreferenced
memory in one big pass?

yes, but unless it's also moving/compacting... one would suffer memory fragmentation... so I would imagine TempAlloc is a better fit?

In some cases I'm comfortable with that type of fragmentation (large regularly sized resources), although that leads me to a gaping hole in D's allocation system...

<OT, but still very important>
There is no way to request aligned memory. I can't even specify an alignment on a user type and expect it to be aligned if I create one on the stack, let alone the heap >_<
It seems I can request alignment for items within a struct, but I can't align the struct its self. In addition, a struct doesn't inherit the alignment of its aligned members, so the struct is allocated unaligned, and the aligned member fails its promise anyway.

I frequently align to:
16 bytes for basically everything. This facilitates hardware simd, fast memcpy, efficient write-combining, better cache usage.
128(ish) bytes for L1 cache alignment (depending on architecture). Frequently used to guarantee ~128byte sized structs will never straddle cache lines (wasting a memory fetch/L1 eviction), and supporting predictable prefetch algorithms.
4k(ish) for texture/gpu page alignment (again, depending on architecture). Many GPU resources MUST be aligned for the GPU to access them. Swizzling is applied to aligned pages, resource allocation must match this.
4-64k virtual memory pages. Many uses.

And occasionally other alignments pop up, often where they may be useful to help reduce/avoid fragmentation for instance.
Sometimes I need to squat some data in a couple of low its in a pointer... requires the pointers be aligned.

Obviously I can manually align my memory with various techniques, and I do, but it's rather fiddly and can also be very wasteful.
One fast technique for general allocations is over-allocating by alignment-1, pasting a little header and padding the allocation. Allocating a GPU page for instance would waste another whole page just to guarantee alignment. In that case, you need to allocate a bog pool of pages and implement some pool system to dish them out, but then you need to know the precise number of pages to be allocated in advance in order not to waste memory that way.
</OT>