Please enable JavaScript to view this site.

Memory Validator Help

The Allocator Alias tab allows you to specify any custom or in-house MACROs used to wrap C/C++ keywords and functions such as new, delete, malloc, realloc, free, etc.

 

This feature was added to improve source code parsing for the case when users have wrapped the keywords.

 

noteThe default behaviour is to have no aliases set, and if you don't wrap the C/C++ keywords in this way, you won't need to define any allocator aliases here.

 

 

allocator-alias-settings

 

The image above shows an example where MY_NEW, MY_NEW_ARRAY, MY_DELETE and MY_DELETE_ARRAY have been used to wrap the C/C++ keywords new, new [], delete and delete [].

 

noteNote: when using allocator and deallocator alias macros, ensure that the macro and all arguments to the macro are on the same source code line. Macros that span lines will not be parsed correctly. This is because the current parser works a line at a time.

 

Allocators

 

To add a custom allocator, use the top table:

 

Add instructionStep enter your custom macro name in the Allocators column instructionStep double click in the Type column instructionStep Choose the matching Allocator Type from the list

 

The allocator type can be one of the following:

 

NEW - new()

NEW [ ] ARRAY - new []

MALLOC - malloc()

CALLOC - calloc()

REALLOC - realloc()

EXPAND - _expand()

HEAP_ALLOC - HeapAlloc()

HEAP_REALLOC - HeapReAlloc()

GLOBAL_ALLOC - GlobalAlloc()

GLOBAL_REALLOC - GlobalReAlloc()

LOCAL_ALLOC - LocalAlloc()

LOCAL_REALLOC - LocalReAlloc()

VIRTUAL_ALLOC - VirtualAlloc()

VIRTUAL_REALLOC - VirtualReAlloc()

COTASKMEM_ALLOC - CoTaskMemAlloc()

COTASKMEM_REALLOC -  CoTaskMemReAlloc()

SYS_ALLOC_STRING - SysAllocString()

SYS_ALLOC_STRING_BYTE_LEN - SysAllocStringByteLen()

SYS_ALLOC_STRING_LEN - SysAllocStringLen()

SYS_REALLOC_STRING - SysReallocString()

SYS_REALLOC_STRING_LEN - SysReallocString()

USER_ALLOC - see below

USER_REALLOC - see below

USER_ALLOC_ARG1...10 - see below

 

 

USER_ALLOC - is a substitute for a user specified alloc where your macro simply replaces a keyword (such as new, malloc, etc)

USER_REALLOC - is for user specified realloc

USER_ALLOC_ARG1...10 - is for a user specified alloc where your macro takes arguments and one of the arguments 1...10 is the allocation. See the end of this topic for example code.

 

 

Deallocators

 

Managing deallocator alias works in the same was as allocators above, but via the lower table, with deallocator types being one of the following:

 

DELETE - delete

DELETE [] ARRAY - delete []

FREE - free()

HEAP_FREE - HeapFree()

GLOBAL_FREE - GlobalFree()

LOCAL_FREE - LocalFree()

VIRTUAL_FREE - VirtualFree()

COTASKMEM_FREE - CoTaskMemFree()

SYS_FREE_STRING - SysFreeString()

VARIANT_CLEAR - VarianctClear()

USER_FREE - user specified free

 

 

Removing aliases

 

You can remove either selected alias or all aliases from each table

 

Select one or more items in the list instructionStep Remove instructionStep removes all selected allocator aliases

Remove All instructionStep removes all the allocators in the table

 

 

Reset All - Resets all global settings but does not remove the allocator and deallocator aliases set on this page of the settings dialog.

 

 

Reset - Resets the settings on the current page.

 

 


 

Example use of the USER_ALLOC_ARG1...10 allocator alias

 

For the USER_ALLOC_ARG1...10 allocator aliases, you would use these in the situation where you have defined a macro that takes arguments, one of which is the allocation.

 

For example, consider the following code:

 

#define PROTECTED_ALLOC1(_allocExpression, _p, dummyArg) \

 try                                                        \

 {                                                        \

         (_p) = (_allocExpression);                        \

 }                                                        \

 catch(...)                                                \

 {                                                        \

         (_p) = NULL;                                        \

 }

 

#define PROTECTED_ALLOC2( _p, _allocExpression, dummyArg) \

 try                                                        \

 {                                                        \

         (_p) = (_allocExpression);                        \

 }                                                        \

 catch(...)                                                \

 {                                                        \

         (_p) = NULL;                                        \

 }

 

 allocateInSideThis        *ec1;

 allocateInSideThis        *ec2;

 char                                *someData;

 

 PROTECTED_ALLOC1(new allocateInSideThis, ec1, false);

 PROTECTED_ALLOC1(new allocateInSideThis[4], ec2, false);

 PROTECTED_ALLOC1((char *)malloc(31), someData, true);

 

 // do some work...

 

 MY_DELETE ec1;        // this one was a single value

 MY_DELETE [] ec2;        // this one was an array

 MY_FREE(someData);        // this one was malloc

 

 PROTECTED_ALLOC2(ec1, new allocateInSideThis, false);

 PROTECTED_ALLOC2(ec2, new allocateInSideThis[4], false);

 PROTECTED_ALLOC2(someData, (char *)malloc(31), true);

 

 // do some work...

 

 MY_DELETE ec1;        // this one was a single value

 MY_DELETE [] ec2;        // this one was an array

 MY_FREE(someData);        // this one was malloc

 

To use the above macros, you would:

 

define PROTECTED_ALLOC1 as a USER_ALLOC_ARG1 since it uses the first argument for the allocation
 

define PROTECTED_ALLOC2 as a USER_ALLOC_ARG2, since it uses the second argument