638
edits
(revise per March 31 meeting (not done yet)) |
(prefer bsmedberg's names) |
||
Line 32: | Line 32: | ||
(BTW we haven't established naming conventions; this is just a sketch) | (BTW we haven't established naming conventions; this is just a sketch) | ||
The idea here is to support allocations of different types: <code> | The idea here is to support allocations of different types: <code>no_pointers</code> allocations are leaf objects and never contain pointers at all; <code>with_layout</code> and <code>array_with_layout</code> allocations have a known layout that governs which fields are pointers; and <code>conservative</code> allocations might contain pointers at any pointer-aligned offset and must be conservatively scanned. | ||
(Where the layout information isn't a speed win, the implementation can of course just discard it. A hacky implementation can just delegate <code> | (Where the layout information isn't a speed win, the implementation can of course just discard it. A hacky implementation can just delegate <code>gc_alloc_with_layout</code> and <code>gc_alloc_array_with_layout</code> to <code>gc_alloc_conservative</code>. Sloppy, but fine by me.) | ||
Line 41: | Line 41: | ||
All allocations are <code>malloc</code>-aligned (that is, alignment is such that the pointer can be cast to any reasonable C/C++ type and used). | All allocations are <code>malloc</code>-aligned (that is, alignment is such that the pointer can be cast to any reasonable C/C++ type and used). | ||
void * ''' | void * '''gc_alloc_no_pointers'''(GCHeap heap, size_t size); | ||
Allocate ''size'' bytes of memory, not necessarily zeroed. The GC will assume the memory never contains pointers to other GC allocations. | Allocate ''size'' bytes of memory, not necessarily zeroed. The GC will assume the memory never contains pointers to other GC allocations. | ||
Line 53: | Line 53: | ||
Allocate ''rawSize'' + ''ptrsSize'' bytes of memory. Both sizes must be pointer-size-aligned. The first ''rawSize'' bytes are not necessarily zeroed. They GC will assume that they never contain pointers. The next ''ptrsSize'' bytes are treated as an array of "possible pointers" (<code>jsval</code>, really; see below). | Allocate ''rawSize'' + ''ptrsSize'' bytes of memory. Both sizes must be pointer-size-aligned. The first ''rawSize'' bytes are not necessarily zeroed. They GC will assume that they never contain pointers. The next ''ptrsSize'' bytes are treated as an array of "possible pointers" (<code>jsval</code>, really; see below). | ||
void * ''' | void * '''gc_alloc_with_layout'''(GCHeap heap, GCLayout layout); | ||
Allocate and zero out memory for an object. The ''layout'' specifies the size of the allocation and which words of it may contain pointers. Layout is described in more detail below. | Allocate and zero out memory for an object. The ''layout'' specifies the size of the allocation and which words of it may contain pointers. Layout is described in more detail below. | ||
void * ''' | void * '''gc_alloc_array_with_layout'''( | ||
GCHeap heap, | |||
GCLayout headerLayout, | |||
GCLayout elementLayout, | |||
size_t count); | |||
Allocate and zero out memory for an array. The layout of the array consists of an optional header described by ''headerLayout'', followed by ''count'' array elements, each described by ''elementLayout''. Returns a pointer to the beginning of the allocation (the header). | Allocate and zero out memory for an array. The layout of the array consists of an optional header described by ''headerLayout'', followed by ''count'' array elements, each described by ''elementLayout''. Returns a pointer to the beginning of the allocation (the header). |
edits