Data Structures | Defines | Typedefs | Functions | Variables

# memory.c File Reference

`#include "wizard/studio.h"`
`#include "wizard/blob.h"`
`#include "wizard/blob-private.h"`
`#include "wizard/exception.h"`
`#include "wizard/exception-private.h"`
`#include "wizard/memory_.h"`
`#include "wizard/semaphore.h"`
`#include "wizard/string_.h"`

## Data Structures
struct | _DataSegmentInfo
struct | _MemoryInfo
struct | _WizardMemoryMethods
## Defines
#define | BlockFooter(block, size) ((size_t *) ((char *) (block)+(size)-2*sizeof(size_t)))
#define | BlockHeader(block) ((size_t *) (block)-1)
#define | BlockSize 4096
#define | BlockThreshold 1024
#define | AlignedSize (16*sizeof(void *))
#define | MaxBlockExponent 16
#define | MaxBlocks ((BlockThreshold/(4*sizeof(size_t)))+MaxBlockExponent+1)
#define | MaxSegments 1024
#define | MemoryGuard ((0xdeadbeef << 31)+0xdeafdeed)
#define | NextBlock(block) ((char *) (block)+SizeOfBlock(block))
#define | NextBlockInList(block) (*(void **) (block))
#define | PreviousBlock(block) ((char *) (block)-(*((size_t *) (block)-2)))
#define | PreviousBlockBit 0x01
#define | PreviousBlockInList(block) (*((void **) (block)+1))
#define | SegmentSize (2*1024*1024)
#define | SizeMask (~0x01)
#define | SizeOfBlock(block) (*BlockHeader(block) & SizeMask)
## Typedefs
typedef struct _DataSegmentInfo | DataSegmentInfo
typedef struct _MemoryInfo | MemoryInfo
typedef struct _WizardMemoryMethods | WizardMemoryMethods
## Functions
static size_t | WizardMax (const size_t x, const size_t y)
WizardExport void * | AcquireAlignedMemory (const size_t count, const size_t quantum)
WizardExport void * | AcquireWizardMemory (const size_t size)
WizardExport void * | AcquireQuantumMemory (const size_t count, const size_t quantum)
WizardExport void * | CopyWizardMemory (void *destination, const void *source, const size_t size)
WizardExport void | DestroyWizardMemory (void)
WizardExport void | GetWizardMemoryMethods (AcquireMemoryHandler *acquire_memory_handler, ResizeMemoryHandler *resize_memory_handler, DestroyMemoryHandler *destroy_memory_handler)
WizardExport void * | RelinquishAlignedMemory (void *memory)
WizardExport void * | RelinquishWizardMemory (void *memory)
WizardExport void * | ResetWizardMemory (void *memory, int byte, const size_t size)
WizardExport void * | ResizeWizardMemory (void *memory, const size_t size)
WizardExport void * | ResizeQuantumMemory (void *memory, const size_t count, const size_t quantum)
WizardExport void | SetWizardMemoryMethods (AcquireMemoryHandler acquire_memory_handler, ResizeMemoryHandler resize_memory_handler, DestroyMemoryHandler destroy_memory_handler)
## Variables
static WizardMemoryMethods | memory_methods

## Define Documentation

#define AlignedSize (16*sizeof(void *))

Referenced by AcquireAlignedMemory().

#define BlockFooter | ( |  | block,
|  |  | size |
| ) |  |  | ((size_t *) ((char *) (block)+(size)-2*sizeof(size_t)))

Referenced by RelinquishWizardMemory().

#define BlockHeader | ( |  | block | ) | ((size_t *) (block)-1)

Referenced by RelinquishWizardMemory().

#define BlockSize 4096

#define BlockThreshold 1024

#define MaxBlockExponent 16

#define MaxBlocks ((BlockThreshold/(4*sizeof(size_t)))+MaxBlockExponent+1)

#define MaxSegments 1024

#define MemoryGuard ((0xdeadbeef << 31)+0xdeafdeed)

#define NextBlock | ( |  | block | ) | ((char *) (block)+SizeOfBlock(block))

Referenced by RelinquishWizardMemory().

#define NextBlockInList | ( |  | block | ) | (*(void **) (block))

#define PreviousBlock | ( |  | block | ) | ((char *) (block)-(*((size_t *) (block)-2)))

Referenced by RelinquishWizardMemory().

#define PreviousBlockBit 0x01

Referenced by RelinquishWizardMemory().

#define PreviousBlockInList | ( |  | block | ) | (*((void **) (block)+1))

#define SegmentSize (2*1024*1024)

#define SizeMask (~0x01)

Referenced by AcquireWizardMemory().

#define SizeOfBlock | ( |  | block | ) | (*BlockHeader(block) & SizeMask)

Referenced by RelinquishWizardMemory().

## Typedef Documentation

typedef struct _DataSegmentInfo DataSegmentInfo

typedef struct _MemoryInfo MemoryInfo

typedef struct _WizardMemoryMethods WizardMemoryMethods

## Function Documentation

WizardExport void* AcquireAlignedMemory | ( | const size_t | count,
|  | const size_t | quantum |
| ) |  |  |

References AlignedSize, and WizardMax().

WizardExport void* AcquireQuantumMemory | ( | const size_t | count,
|  | const size_t | quantum |
| ) |  |  |

References AcquireWizardMemory().

Referenced by AcquireAESInfo(), AcquireBZIPMemory(), AcquireCRC64Info(), AcquireLZMAMemory(), AcquireMD5Info(), AcquireSHA1Info(), AcquireSHA224Info(), AcquireSHA256Info(), AcquireSHA384Info(), AcquireSHA512Info(), AcquireString(), AcquireStringInfo(), AcquireZIPMemory(), BalanceSplayTree(), Base64Decode(), Base64Encode(), ConfigureFileToStringInfo(), ConstantString(), ConvertLatin1ToUTF8(), ConvertUTF16ToUTF8(), FileToBlob(), GetConfigureInfoList(), GetConfigureList(), GetExecutionPath(), GetHashHexDigest(), GetLogInfoList(), GetLogList(), GetMimeInfoList(), GetMimeList(), GetPathComponents(), GetWizardOptions(), IncreaseHashmapCapacity(), IterateOverSplayTree(), NewHashmap(), NewXMLTree(), ParseEntities(), ParseInternalDoctype(), ParseProcessingInstructions(), SetStringInfoLength(), SetXMLTreeAttribute(), StringInfoToHexString(), StringInfoToString(), and StringToArgv().

WizardExport void* AcquireWizardMemory | ( | const size_t | size | ) |

References _WizardMemoryMethods::acquire_memory_handler, AcquireSemaphoreInfo(), LockSemaphoreInfo(), memory_methods, ResetWizardMemory(), SizeMask, UnlockSemaphoreInfo(), and WizardFalse.

Referenced by AcquireAESInfo(), AcquireAuthenticateInfo(), AcquireBZIPInfo(), AcquireCipherInfo(), AcquireCRC64Info(), AcquireEntropyInfo(), AcquireExceptionInfo(), AcquireFileInfo(), AcquireHashInfo(), AcquireHMACInfo(), AcquireKeyInfo(), AcquireKeyringInfo(), AcquireLZMAInfo(), AcquireMD5Info(), AcquireQuantumMemory(), AcquireRandomInfo(), AcquireSecretInfo(), AcquireSerpentInfo(), AcquireSHA1Info(), AcquireSHA224Info(), AcquireSHA256Info(), AcquireSHA384Info(), AcquireSHA512Info(), AcquireStringInfo(), AcquireTimerInfo(), AcquireTwofishInfo(), AcquireZIPInfo(), AddChildToXMLTree(), AddValueToSplayTree(), AppendValueToLinkedList(), InsertValueInLinkedList(), InsertValueInSortedLinkedList(), LoadConfigureList(), LoadConfigureLists(), LoadLogList(), LoadLogLists(), LoadMimeList(), NewHashmap(), NewLinkedList(), NewSplayTree(), NewXMLTreeTag(), OpenBlob(), ParseInternalDoctype(), ParseProcessingInstructions(), PutEntryInHashmap(), ResizeWizardMemory(), ThrowException(), and WizardCreateThreadKey().

WizardExport void* CopyWizardMemory | ( | void * | destination,
|  | const void * | source,
|  | const size_t | size |
| ) |  |  |

Referenced by AcquireRandomInfo(), ConvertUTF16ToUTF8(), GetPathComponent(), GetPhrase(), NewXMLTreeTag(), ParseEntities(), ParseInternalDoctype(), SetAESKey(), SetRandomKey(), SetXMLTreeAttribute(), SubstituteString(), UpdateSHA1(), UpdateSHA224(), UpdateSHA256(), UpdateSHA384(), UpdateSHA512(), and UpdateSignature().

WizardExport void DestroyWizardMemory | ( | void |  | ) |

References AcquireSemaphoreInfo(), _WizardMemoryMethods::destroy_memory_handler, DestroySemaphoreInfo(), LockSemaphoreInfo(), memory_methods, ResetWizardMemory(), UnlockSemaphoreInfo(), UnmapBlob(), and WizardFalse.

WizardExport void GetWizardMemoryMethods | ( | AcquireMemoryHandler * | acquire_memory_handler,
|  | ResizeMemoryHandler * | resize_memory_handler,
|  | DestroyMemoryHandler * | destroy_memory_handler |
| ) |  |  |

References _WizardMemoryMethods::acquire_memory_handler, _WizardMemoryMethods::destroy_memory_handler, memory_methods, and _WizardMemoryMethods::resize_memory_handler.

WizardExport void* RelinquishAlignedMemory | ( | void * | memory | ) |

WizardExport void* RelinquishWizardMemory | ( | void * | memory | ) |

References BlockFooter, BlockHeader, _WizardMemoryMethods::destroy_memory_handler, LockSemaphoreInfo(), memory_methods, NextBlock, PreviousBlock, PreviousBlockBit, SizeOfBlock, and UnlockSemaphoreInfo().

Referenced by AcquireFileInfo(), AddPathToXMLTree(), BalanceSplayTree(), Base64Decode(), CanonicalXMLContent(), ClearLinkedList(), CloneString(), ConfigureFileToStringInfo(), DeleteNodeByValueFromSplayTree(), DeleteNodeFromSplayTree(), DestroyAESInfo(), DestroyAuthenticateInfo(), DestroyBlob(), DestroyBZIPInfo(), DestroyCipherInfo(), DestroyConfigureElement(), DestroyCRC64Info(), DestroyEntropyInfo(), DestroyExceptionElement(), DestroyExceptionInfo(), DestroyFileInfo(), DestroyHashInfo(), DestroyHashmap(), DestroyHMACInfo(), DestroyKeyInfo(), DestroyKeyringInfo(), DestroyLinkedList(), DestroyLogElement(), DestroyLZMAInfo(), DestroyMD5Info(), DestroyMimeElement(), DestroyRandomInfo(), DestroySecretInfo(), DestroySerpentInfo(), DestroySHA1Info(), DestroySHA224Info(), DestroySHA256Info(), DestroySHA384Info(), DestroySHA512Info(), DestroySplayTree(), DestroyString(), DestroyStringInfo(), DestroyStringList(), DestroyTimerInfo(), DestroyTwofishInfo(), DestroyXMLTree(), DestroyXMLTreeAttributes(), DestroyZIPInfo(), FileToBlob(), GetConfigureOptions(), GetConfigurePaths(), GetExecutionPath(), GetPathTemplate(), GetXMLTreePath(), IncreaseHashmapCapacity(), InsertValueInSortedLinkedList(), IterateOverSplayTree(), ListConfigureInfo(), ListLogInfo(), ListMimeInfo(), LoadConfigureList(), LoadLogList(), LogWizardEventList(), OpenBlob(), ParseInternalDoctype(), PutEntryInHashmap(), RelinquishBZIPMemory(), RelinquishLZMAMemory(), RelinquishZIPMemory(), RemoveElementByValueFromLinkedList(), RemoveElementFromLinkedList(), RemoveEntryFromHashmap(), RemoveLastElementFromLinkedList(), RemoveNodeByValueFromSplayTree(), RemoveNodeFromSplayTree(), ResetSplayTree(), ResizeQuantumMemory(), ResizeWizardMemory(), StringToArgv(), WizardDeleteThreadKey(), WizardOpenStream(), and WizardsToolkitGenesis().

WizardExport void* ResetWizardMemory | ( | void * | memory,
|  | int | byte,
|  | const size_t | size |
| ) |  |  |

Referenced by AcquireAESInfo(), AcquireAuthenticateInfo(), AcquireBZIPInfo(), AcquireCipherInfo(), AcquireCRC64Info(), AcquireEntropyInfo(), AcquireExceptionInfo(), AcquireFileInfo(), AcquireHashInfo(), AcquireHMACInfo(), AcquireKeyInfo(), AcquireKeyringInfo(), AcquireLZMAInfo(), AcquireMD5Info(), AcquireRandomInfo(), AcquireSecretInfo(), AcquireSerpentInfo(), AcquireSHA1Info(), AcquireSHA224Info(), AcquireSHA256Info(), AcquireSHA384Info(), AcquireSHA512Info(), AcquireStringInfo(), AcquireTimerInfo(), AcquireTwofishInfo(), AcquireWizardMemory(), AcquireZIPInfo(), AddChildToXMLTree(), AllocateSemaphoreInfo(), DecipherAESBlock(), DecipherCBCMode(), DecipherCFBMode(), DecipherCTRMode(), DecipherOFBMode(), DestroyRandomInfo(), DestroyWizardMemory(), EncipherAESBlock(), EncipherCBCMode(), EncipherCFBMode(), EncipherCTRMode(), EncipherOFBMode(), FinalizeMD5(), FinalizeSHA1(), FinalizeSHA224(), FinalizeSHA256(), FinalizeSHA384(), FinalizeSHA512(), FinalizeSignature(), GetBlobInfo(), GetExceptionInfo(), GetPhrase(), GetSignatureInfo(), HexStringToStringInfo(), IncreaseHashmapCapacity(), IncreaseLZMA(), LoadConfigureList(), LoadConfigureLists(), LoadLogList(), LoadLogLists(), LoadMimeList(), NewHashmap(), NewLinkedList(), NewSplayTree(), NewXMLTreeTag(), OpenBlob(), ParseWizardTime(), PrintKeyringProperties(), ResetStringInfo(), RestoreLZMA(), SetAESKey(), SetStringInfo(), SetTwofishKey(), ThrowException(), TransformSHA1(), TransformSHA224(), TransformSHA256(), TransformSHA384(), TransformSHA512(), and UpdateMD5().

WizardExport void* ResizeQuantumMemory | ( | void * | memory,
|  | const size_t | count,
|  | const size_t | quantum |
| ) |  |  |

References RelinquishWizardMemory(), and ResizeWizardMemory().

Referenced by CanonicalXMLContent(), CloneString(), ConcatenateString(), ConvertUTF16ToUTF8(), EncodePredefinedEntities(), FileToBlob(), NewXMLTree(), ParseEntities(), ParseInternalDoctype(), ParseProcessingInstructions(), SetBlobExtent(), SetStringInfoLength(), SetXMLTreeAttribute(), SubstituteString(), TranslateEvent(), TranslateFilename(), WriteBlob(), XMLTreeInfoToXML(), and XMLTreeTagToXML().

WizardExport void* ResizeWizardMemory | ( | void * | memory,
|  | const size_t | size |
| ) |  |  |

References AcquireWizardMemory(), LockSemaphoreInfo(), memory_methods, RelinquishWizardMemory(), _WizardMemoryMethods::resize_memory_handler, ThrowFatalException, UnlockSemaphoreInfo(), and WizardFalse.

Referenced by ResizeQuantumMemory().

WizardExport void SetWizardMemoryMethods | ( | AcquireMemoryHandler | acquire_memory_handler,
|  | ResizeMemoryHandler | resize_memory_handler,
|  | DestroyMemoryHandler | destroy_memory_handler |
| ) |  |  |

References _WizardMemoryMethods::acquire_memory_handler, _WizardMemoryMethods::destroy_memory_handler, memory_methods, and _WizardMemoryMethods::resize_memory_handler.

static size_t WizardMax | ( | const size_t | x,
|  | const size_t | y |
| ) |  |  | `[inline, static]`

Referenced by AcquireAlignedMemory().

## Variable Documentation

WizardMemoryMethods memory_methods`[static]`

Initial value:

      {
        (AcquireMemoryHandler) malloc,
        (ResizeMemoryHandler) realloc,
        (DestroyMemoryHandler) free
      }

Referenced by AcquireWizardMemory(), DestroyWizardMemory(), GetWizardMemoryMethods(), RelinquishWizardMemory(), ResizeWizardMemory(), and SetWizardMemoryMethods().