This wiki is being migrated to http://www.github.com/z88dk/z88dk/wiki

 

Differences

This shows you the differences between two versions of the page.

libnew:alloc_malloc [2015/08/28 03:03]
aralbrec Completed
libnew:alloc_malloc [2016/12/25 16:02] (current)
aralbrec
Line 2: Line 2:
^ Include    | #include <malloc.h> or #include <alloc/malloc.h>      | ^ Include    | #include <malloc.h> or #include <alloc/malloc.h>      |
-^ Header    | [[http://z88dk.cvs.sourceforge.net/viewvc/z88dk/z88dk/include/_DEVELOPMENT/sccz80/alloc/malloc.h|{z88dk}/include/_DEVELOPMENT/sccz80/alloc/malloc.h]] | +^ Header    | [[http://z88dk.cvs.sourceforge.net/viewvc/z88dk/z88dk/include/_DEVELOPMENT/sccz80/alloc/malloc.h?content-type=text%2Fplain|{z88dk}/include/_DEVELOPMENT/sccz80/alloc/malloc.h]] | 
-^            | [[http://z88dk.cvs.sourceforge.net/viewvc/z88dk/z88dk/include/_DEVELOPMENT/sdcc/alloc/malloc.h|{z88dk}/include/_DEVELOPMENT/sdcc/alloc/malloc.h]] +^            | [[http://z88dk.cvs.sourceforge.net/viewvc/z88dk/z88dk/include/_DEVELOPMENT/sdcc/alloc/malloc.h?content-type=text%2Fplain|{z88dk}/include/_DEVELOPMENT/sdcc/alloc/malloc.h]] |
-^ Source    | [[http://z88dk.cvs.sourceforge.net/viewvc/z88dk/z88dk/libsrc/_DEVELOPMENT/alloc/malloc|{z88dk}/libsrc/_DEVELOPMENT/alloc/malloc]]                    |+
Other References: Other References:
 +  * [[http://www.gnu.org/software/libc/manual/html_node/Unconstrained-Allocation.html#Unconstrained-Allocation|GNU libc Manual]]
  * [[http://pubs.opengroup.org/onlinepubs/9699919799/|The Open Group]]   * [[http://pubs.opengroup.org/onlinepubs/9699919799/|The Open Group]]
  * [[http://z88dk.cvs.sourceforge.net/viewvc/z88dk/z88dk/libsrc/_DEVELOPMENT/c11_n1570.pdf|The C11 Draft Standard]]   * [[http://z88dk.cvs.sourceforge.net/viewvc/z88dk/z88dk/libsrc/_DEVELOPMENT/c11_n1570.pdf|The C11 Draft Standard]]
Line 13: Line 13:
The C11 standard requires that the malloc-related functions be protected by a lock against simultaneous access from multiple threads.  The library implements these locks but they are deactivated by default in the [[temp:front#library_configuration|library configuration]].  These locks should remain deactivated until the library has incorporated multithreading. The C11 standard requires that the malloc-related functions be protected by a lock against simultaneous access from multiple threads.  The library implements these locks but they are deactivated by default in the [[temp:front#library_configuration|library configuration]].  These locks should remain deactivated until the library has incorporated multithreading.
-Dynamic memory is allocated out of the heap.  The heap is a single contiguous block of memory whose size is set at compile-time by the [[temp:front#crt|crt configuration]] and is typically 1024 bytes by default.  The actual memory space required by the heap is reserved in the BSS section.+Dynamic memory is allocated out of the heap.  The heap is a single contiguous block of memory whose size is set at either compile-time or runtime depending on the [[temp:front#crt|crt configuration]].  The actual memory space used by the heap will either be reserved in the BSS section or it will lie between the end of the BSS section and the stack.
-**THE** heap refers to the particular heap implied by the standard C library functions malloc, free, etc.  The library allows the creation of multiple heaps from which allocations can occur using the named heap API.  The only difference between the standard C library functions and the named heap API is that the named heap functions must be supplied the address of the heap to allocate from.  The address of the standard library's implied heap is **%%__malloc_heap%%** and if this is given to the named heap API, those functions will allocate out of the same heap as the standard C library functions.+**THE** heap refers to the particular heap implied by the standard C library functions malloc, free, etc.  The library allows the creation of multiple heaps from which allocations can occur using the named heap API.  The only difference between the standard C library functions and the named heap API is that the named heap functions must be supplied the address of the heap to allocate from.  The address of the standard library's implied heap is **%%__malloc_heap%%** (C name "_malloc_heap") and if this is given to the named heap API, those functions will allocate out of the same heap as the standard C library functions.
-There are three purposes served by the named heap API:+There are four purposes served by the named heap API:
-  * Available memory from disjoint areas of the memory map can be assigned to multiple heaps and used as a dynamic memory pool. +  * Available memory from disjoint areas of the memory map can be assigned to different heaps and used as a dynamic memory pool. 
-  * Individual heaps can be assigned to allocate memory for different purposes.  This may help to solve fragmentation issues but it can also help in a bankswitched memory map -- one heap or another may be paged out and therefore unavailable in certain banking configurations+  * Individual heaps can be assigned to allocate memory for different purposes.  This may help to solve fragmentation issues. 
-  * Heaps can be created to make use of memory in multiple memory banks.+  * Heaps can be created in different memory banks
 +  * In a multithreading environment, threads can be given their own heaps so that blocking isn't an issue.
When allocating or freeing from a heap, the entire heap must be paged in. When allocating or freeing from a heap, the entire heap must be paged in.
Line 128: Line 129:
====== NAMED HEAP - MEMORY MANAGEMENT FUNCTIONS ====== ====== NAMED HEAP - MEMORY MANAGEMENT FUNCTIONS ======
-//%%__malloc_heap%%// is the address of the standard library's heap.+//%%__malloc_heap%%// holds the address of the standard library's heap.  The 16-bit value stored there is the address that should be passed as //heap// in the functions below if allocation out of the standard library's heap is desired.  //heap// is the address of the memory block used for allocation.
==== void *heap_alloc(void *heap, size_t size) ==== ==== void *heap_alloc(void *heap, size_t size) ====
Line 142: Line 143:
See _falloc_().  Allocates out of the heap //heap//. See _falloc_().  Allocates out of the heap //heap//.
-===== void *heap_calloc(void *heap, size_t nmemb, size_t size) =====+==== void *heap_calloc(void *heap, size_t nmemb, size_t size) ====
See calloc().  Allocates out of the heap //heap//. See calloc().  Allocates out of the heap //heap//.
 
libnew/alloc_malloc.1440727417.txt.gz · Last modified: 2015/08/28 03:03 by aralbrec
 
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki