Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields   Globals  

Memory.c

Go to the documentation of this file.
00001 /******************************************************************
00002         ANet_Daemon/Common/Memory.c
00003         Memory management for the run-time wrapper of the daemon.
00004         
00005         Part of the ANet project.
00006         
00007         Distributed under GPL: http://www.gnu.org/copyleft/gpl.html
00008 ******************************************************************/
00009 
00010 #include "Memory.h"
00011 #include <stdlib.h>
00012 
00024 /*
00025   Current memory format:
00026   ANetMemoryTag is a memory location.
00027   The first 4 bytes are the size of the block.
00028   The remaining bytes is the data itself.
00029 */
00030 
00039 UInt32 IsTagValid(ANetMemoryTag tag)
00040 {
00041   return (tag != 0); 
00042 }
00043 
00059 ANetMemoryTag NewMemoryBlock(UInt32 size, UInt32 flags)
00060 {
00061   // Soft-limit of 500MB assumed
00062   UInt32 *mem;
00063   if (size & 0xC0000000)
00064   {
00065     return (ANetMemoryTag)(0);
00066   }
00067   mem = (UInt32*)(malloc(size + sizeof(UInt32)));
00068   mem[0] = size;
00069   return (ANetMemoryTag)(mem);
00070 }
00071 
00083 UInt32 DeleteMemoryBlock(ANetMemoryTag tag)
00084 {
00085   if (!tag)
00086     return 1;
00087   free((char*)(tag));
00088   return 0;
00089 }
00090 
00102 UInt32 GetMemoryBlockSize(ANetMemoryTag tag)
00103 {
00104   return *(UInt32*)(tag);
00105 }
00106 
00123 UInt32 ResolveMemoryTag(ANetMemoryTag tag, UInt8 **ptr)
00124 {
00125   // Soft-limit of 500MB assumed
00126   if (!tag)
00127     return 1;
00128   if (!ptr)
00129     return 2;
00130   if (*((UInt32*)(tag)) & 0xC0000000)
00131     return 1;
00132   *ptr = (UInt8*)((UInt32*)(tag) + 1);
00133   return 0;
00134 }
00135 

Generated on Sun Dec 23 15:20:37 2001 for ANet by doxygen 1.2.12 written by Dimitri van Heesch, © 1997-2001

SourceForge
Logo