1 out of 1 rated this helpful - Rate this topic

Alloc Function

Allocates a block of memory of the size specified from the Concurrency Runtime's Caching Suballocator.

_CRTIMP void * __cdecl Alloc(    size_t _NumBytes );
_NumBytes

The number of bytes of memory to allocate.

A pointer to newly allocated memory.

Use the caching suballocator when you expect to make several allocations interspersed with deallocations with a small set of block sizes on a number of threads. The suballocator is a caching layer above the C Runtime heap. The Concurrency Runtime creates a suballocator per virtual processor in a scheduler, as well as one sub allocator per thread created by your application that uses the allocator methods.

Once you have built up a cache of a certain size block, allocations and frees are possible without holding locks or even executing memory barriers. If the cache in each suballocator for a block size is empty, allocations are made from the heap, and if the cache has reached a certain size for a block size, the blocks are free to the C Runtime heap.

If your application uses a large amount of memory you may find that you run out of memory sooner than you exepct if you use the caching suballocator. This is because blocks cached in one suballocator are not available to another, and there may be large amounts of memory cached in suballocators that a particular thread has no access to at a particular point.

Header: concrt.h

Namespace: Concurrency

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Alignment?
I can't find any mention of memory alignment in the documentation on Concurrency::Alloc, and it appears as though it only aligns at 8-byte boundaries in my basic tests. This means that you cannot use it out of the box for allocating anything containing SSE vectors since these require 16-byte alignment. It would be nice if the API could be extended with allocation functions allowing arbitrary alignment. $0 $0$0 $0 $0