2.8.1.9. alloc_Merge()

[<<<] [>>>]

Call this function in case you want to merge a segment into another. This can be the case when your program builds up a memory structure in several steps.

This function merges the segment p2 into p1. This means that the segment p1 will contain all the memory pieces that belonged to p2 before and p2 will not contain any allocated memory. However the segment p2 is still valid and can be used to allocated memory from. If you also want to finish the segment p2 call the function @xref{alloc_MergeAndFinish()}.

void alloc_Merge(void *p1, void *p2
  ){

Note that the two segments SHOULD use the same, or at least compatible system memory handling functions! You better use the same functions for both segments.

Example:

ScriptBasic builds up a sophisticated memory structure during syntactical analysis. This memory structure contains the internal code generated from the program lines of the basic program. When ScriptBasic analyses a line it tries several syntax descriptions. It checks each syntax defintion against the tokens of the line until it finds one that fits. These checks need to build up memory structure. However if the check fails and ScriptBasic should go for the next syntac definition line to check the memory allocated during the failed checking should be released. Therefore these memory pieces are allocated from a segment that the program calls pMyMemorySegment. If the syntax check fails this segment if freed. If the syntax check succedes this segment is merged into another segement that contains the memory structures allocated from the previous basic program lines.


[<<<] [>>>]