How the Nasal GC works: Difference between revisions

Jump to navigation Jump to search
m
Line 7: Line 7:


A memory pool is basically a preallocated region of memory
A memory pool is basically a preallocated region of memory
The interesting part is the naGC_get() function which isn't directly mapped to naAlloc() or malloc(), but instead manages the Nasal memory pools.
For each native Nasal data type (scalars, vectors, hashes, funcs etc) , there are separate memory pools in globals->pools[n]. The index (n) is one of T_VEC, T_HASH, T_FUNC etc.


== Nasal memory pools ==
== Nasal memory pools ==
Line 96: Line 93:


The size of a memory pool is determined using poolsize(): https://gitorious.org/fg/simgear/blobs/next/simgear/nasal/gc.c#line186
The size of a memory pool is determined using poolsize(): https://gitorious.org/fg/simgear/blobs/next/simgear/nasal/gc.c#line186


<syntaxhighlight lang="C">
<syntaxhighlight lang="C">
Line 111: Line 107:
All high level type allocators (naNewString, naNewVector, naNewHash etc) make use of the naNew() call introduced earlier.
All high level type allocators (naNewString, naNewVector, naNewHash etc) make use of the naNew() call introduced earlier.
naNew() doesn't directly allocate new memory from the heap, but instead use the naGC_get() helper which manages pool memory.
naNew() doesn't directly allocate new memory from the heap, but instead use the naGC_get() helper which manages pool memory.
The interesting part is the naGC_get() function which isn't directly mapped to naAlloc() or malloc(), but instead manages the Nasal memory pools.
For each native Nasal data type (scalars, vectors, hashes, funcs etc) , there are separate memory pools in globals->pools[n]. The index (n) is one of T_VEC, T_HASH, T_FUNC etc.


The naGC_get() pool "manager" is located in gc.nas line 194: https://gitorious.org/fg/simgear/blobs/next/simgear/nasal/gc.c#line194
The naGC_get() pool "manager" is located in gc.nas line 194: https://gitorious.org/fg/simgear/blobs/next/simgear/nasal/gc.c#line194

Navigation menu