Category: MySQLDevelopment

MySQL Internals How to allocate memory

← Back to MySQL Internals overview page

[edit] How to allocate memory in the MySQL server (sql directory)

The basic logic to use:

All things that are used only for the duration of a query are allocated in THD::mem_root through sql_alloc() or thd->alloc() except:

Things that are needed a longer time should be alllocated with my_malloc() or through another MEMROOT.

Some objects have their own MEMROOT:

[edit] How to allocate memory in a library or storage engine

For the simple case, use the functions in mysys/my_malloc.c:

Alternatively, if you want to allocate many pieces at once, use my_multi_malloc() from mysys/mulalloc.c


For the complex case where you want to allocate a lot and free things at once, use the MEM_ROOT object defined in mysys/my_alloc.c

Functions to use:

Retrieved from "http://forge.mysql.com/wiki/MySQL_Internals_How_to_allocate_memory"

This page has been accessed 9,203 times. This page was last modified 22:06, 24 January 2011.

Find

Browse
MySQLForge
Main Page
Current events
Recent changes
Random page
Help
Edit
Edit this page
Editing help
This page
Discuss this page
Post a comment
Printable version
Context
Page history
What links here
Related changes
My pages
Special pages
New pages
File list
Statistics
Bug reports
More...