C Interface to Scalable Allocator

Summary

Low level interface for scalable memory allocation.

Syntax

        extern "C" {
            // Scalable analogs of C memory allocator
            void* scalable_malloc( size_t size );
            void  scalable_free( void* ptr );
            void* scalable_calloc( size_t nobj, size_t size );
            void* scalable_realloc( void* ptr, size_t size );
         
            // Analog of _msize/malloc_size/malloc_usable_size.
            size_t scalable_msize( void* ptr );
         
            // Scalable analog of posix_memalign
            int scalable_posix_memalign( void** memptr, size_t alignment, 
                                         size_t size );
         
            // Aligned allocation
            void* scalable_aligned_malloc( size_t size, 
                                           size_t alignment);
            void scalable_aligned_free( void* ptr ); 
            void* scalable_aligned_realloc( void* ptr, size_t size, 
                                            size_t alignment );

            // Return values for scalable_allocation_* functions
            typedef enum {
                TBBMALLOC_OK,
                TBBMALLOC_INVALID_PARAM,
                TBBMALLOC_UNSUPPORTED,
                TBBMALLOC_NO_MEMORY,
                TBBMALLOC_NO_EFFECT
            } ScalableAllocationResult;

            typedef enum {
                TBBMALLOC_USE_HUGE_PAGES,  // value turns using huge pages on and off
            } AllocationModeParam;

            // Set allocator-specific allocation modes.
            int scalable_allocation_mode(int param, intptr_t value);

            typedef enum {
                // Clean internal allocator buffers for all threads.
                TBBMALLOC_CLEAN_ALL_BUFFERS,
                // Clean internal allocator buffer for current thread only.
                TBBMALLOC_CLEAN_THREAD_BUFFERS
            } ScalableAllocationCmd;

            // Call allocator-specific commands.
            int scalable_allocation_command(int cmd, void *param);


        }

Header

#include "tbb/scalable_allocator.h"

Description

These functions provide a C level interface to the scalable allocator. With the exception of scalable_allocation_mode and scalable_allocation_command, each routine scalable_x behaves analogously to library function x. The routines form the two families shown in the table below, "C Interface to Scalable Allocator" . Storage allocated by a scalable_x function in one family must be freed or resized by a scalable_x function in the same family, not by a C standard library function. Likewise storage allocated by a C standard library function should not be freed or resized by a scalable_x function.

C Interface to Scalable Allocator

Family

Allocation Routine

Deallocation Routine

Analogous Library

1

scalable_malloc

scalable_free

C standard library

scalable_calloc

scalable_realloc

scalable_posix_memalign

POSIX*

2

scalable_aligned_malloc

scalable_aligned_free

Microsoft* C run-time library

scalable_aligned_realloc

size_t scalable_msize( void* ptr )

Returns

The usable size of the memory block pointed to by ptr if it was allocated by the scalable allocator. Returns zero if ptr does not point to such a block.

int scalable_allocation_mode(int mode, intptr_t value)

This function may be used to adjust behavior of the scalable memory allocator.

Returns: TBBMALLOC_OK if the operation succeeded, TBBMALLOC_INVALID_PARAM if mode is not one of the described below, or if value is not valid for the given mode. Other return values are possible, as described below.

Parameter Description
TBBMALLOC_USE_HUGE_PAGES

scalable_allocation_mode(TBBMALLOC_USE_HUGE_PAGES, 1) enables the use of huge pages by the allocator if supported for the operating system, scalable_allocation_mode(TBBMALLOC_USE_HUGE_PAGES, 0) disables it. Setting TBB_MALLOC_USE_HUGE_PAGES environment variable to 1 has same affect as scalable_allocation_mode(TBBMALLOC_USE_HUGE_PAGES, 1). The mode set with scalable_allocation_mode() takes priority over the environment variable.

May return: TBBMALLOC_NO_EFFECT if huge pages are not supported on the platform.

int scalable_allocation_command(int cmd, void *reserved)

This function may be used to command the scalable memory allocator to perform an action specified by the first parameter. The second parameter is reserved and must be set to 0.

Returns: TBBMALLOC_OK if the operation succeeded, TBBMALLOC_INVALID_PARAM if cmd is not one of the described below, or if reserved is not equal to 0.

Parameter Description
TBBMALLOC_CLEAN_ALL_BUFFERS

scalable_allocation_command(TBBMALLOC_CLEAN_ALL_BUFFERS, 0) cleans internal memory buffers of the allocator, and possibly reduces memory footprint. It may result in increased time for subsequent memory allocation requests. The command is not designed for frequent use, and careful evaluation of the performance impact is recommended.

May return: TBBMALLOC_NO_EFFECT if no buffers were released.

TBBMALLOC_CLEAN_THREAD_BUFFERS

scalable_allocation_command(TBBMALLOC_CLEAN_THREAD_BUFFERS, 0) cleans internal memory buffers but only for the calling thread. It may result in increased time for subsequent memory allocation requests; careful evaluation of the performance impact is recommended.

May return: TBBMALLOC_NO_EFFECT if no buffers were released.

Para obter informações mais completas sobre otimizações do compilador, consulte nosso aviso de otimização.