Get the App
SLTechnology News&Howtos  ›  Servers  › 

What is the memory allocation strategy in AGG?

Shulou Source: shulou.com Published: 2022-06-01 02:09:18 09月21日 Update

This article mainly shows you "what is the memory allocation strategy in AGG", which is easy to understand and clear. I hope it can help you solve your doubts. Let me lead you to study and learn what the memory allocation strategy is in AGG.

Description

AGG uses the new/delete function to manipulate heap memory, which is sometimes not the best choice. On the other hand, STL's memory allocation strategy is too cumbersome to adopt. Describe the current memory allocation policy in the agg_allocator.h file:

Template struct allocator

{

Static T* allocate_array (unsigned size) {return new T [size];}

Static void free_array (T* v, unsigned) {delete [] v;}

}

The specific usage is as follows:

Char* array = allocator::allocate_array (size)

Allocator::free_array (array)

Understand

All memory allocations are done in this way, and there is no array that requires initialization of array elements. All allocation data is of type POD. POD type is considered to be the structure of C language, does not carry any class features, and can easily memcpy or strcpy.

You can customize the memory allocator, for example:

Template struct allocator

{

Static T* allocate_array (unsigned size)

{

Return (T*) malloc (sizeof (T) * size)

}

Static void free_array (T* v, unsigned size)

{

If (v) free (v)

}

}

Application scenario: create custom super efficient heap memory

These are all the contents of the article "what is the memory allocation strategy in AGG?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Memory allocation policy content articles arrays types learning help tedious elements functions allocators on the other hand scenarios data files methods easy to understand more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Docker NVidia OPPO Reno Huawei