On 19 August 2013 10:52, Stefan Dösinger <ste...@codeweavers.com> wrote: > +struct wined3d_heap_memory *wined3d_alloc_resource_mem(UINT size) > +{ > + struct wined3d_heap_memory *ret; > + > + ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret)); > + if (!ret) > + return NULL; > + > + ret->alloc_ptr = HeapAlloc(GetProcessHeap(), 0, size + > RESOURCE_ALIGNMENT); > + if (!ret->alloc_ptr) > + { > + HeapFree(GetProcessHeap(), 0, ret); > + return NULL; > + } > + ret->ptr = (BYTE *)(((ULONG_PTR)ret->alloc_ptr > + + (RESOURCE_ALIGNMENT - 1)) & ~(RESOURCE_ALIGNMENT - 1)); > + return ret; > +} > +
I don't think this is a good idea. How about something like the following? The corresponding free function would be trivial. void *wined3d_memalign(SIZE_T alignment, SIZE_T size) { SIZE_T align; void *mem; void **p; align = max(sizeof(*p), alignment - 1); if (!(mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size + align))) return NULL; p = (void **)(((ULONG_PTR)mem + align) & ~(alignment - 1)) - 1; *p = mem; return ++p; } (Untested, there's probably some room for improvement.)