[Anet-checkins] CVS: ANet/ANet_Daemon/Core Memory.c,NONE,1.1
Status: Abandoned
Brought to you by:
benad
From: Benoit N. <be...@us...> - 2001-11-11 17:50:26
|
Update of /cvsroot/anet/ANet/ANet_Daemon/Core In directory usw-pr-cvs1:/tmp/cvs-serv30333/Core Added Files: Memory.c Log Message: Added Memory Management (MM) Stubs --- NEW FILE: Memory.c --- /****************************************************************** ANet_Daemon/Core/Memory.c Memory management for the run-time wrapper of the daemon. Part of the ANet project. Distributed under GPL: http://www.gnu.org/copyleft/gpl.html ******************************************************************/ #include "Memory.h" #include <stdlib.h> /* Current memory format: ANetMemoryTag is a memory location. The first 4 bytes are the size of the block. The remaining bytes is the data itself. */ ANetMemoryTag NewMemoryBlock(UInt32 size, UInt32 flags) { // Soft-limit of 500MB assumed UInt32 *mem; if (size & 0xC0000000) { return (ANetMemoryTag)(0); } mem = (UInt32*)(malloc(size + sizeof(UInt32))); mem[0] = size; return (ANetMemoryTag)(mem); } UInt32 DeleteMemoryBlock(ANetMemoryTag tag) { if (!tag) return 1; free((char*)(tag)); return 0; } UInt32 GetMemoryBlockSize(ANetMemoryTag tag) { return *(UInt32*)(tag); } UInt32 ResolveMemoryTag(ANetMemoryTag tag, UInt8 **ptr) { // Soft-limit of 500MB assumed if (!tag) return 1; if (!ptr) return 1; if (*((UInt32*)(tag)) & 0xC0000000) return 1; *ptr = (UInt8*)((UInt32*)(tag) + 1); return 0; } |