Megosztás a következőn keresztül:


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 );

Parameters

  • _NumBytes
    The number of bytes of memory to allocate.

Return Value

A pointer to newly allocated memory.

Remarks

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 expect 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.

Requirements

Header: concrt.h

Namespace: Concurrency

See Also

Reference

Concurrency Namespace

Free Function