/* librock/ialloco.h NOTE: This file is intended to be included from librock/mstruct.h See http://www.mibsoftware.com/librock/ for documentation and original copies of this software. This software shall be distributed with the implementation source code according to the license terms of the source code. License text in librock_LIDESC_HC=12440211096131f5976d36be0cddca4cd9152e45 */ /* $Log: ialloco.h,v $ Revision 1.3 2002/02/10 03:18:46 forrest@mibsoftware.com rights=#1 Standardized chg log. // removal Revision 1.2 2002/01/29 04:40:02 forrest@mibsoftware.com rights=#1 Prep for publish. API clean up, TAB, space at eol removal Revision 1.1 2001/01/06 19:36:17 forrest@mibsoftware.com rights=#1 Initial import to CVS rights#1 Copyright (c) Forrest J Cavalier III d-b-a Mib Software rights#1 License text in librock_LIDESC_HC=12440211096131f5976d36be0cddca4cd9152e45 */ #ifdef __cplusplus #ifdef librock_uint32_t_defined class librock_CAllocOffset32 { /* Allocate and store blocks which are referenced by offset */ protected: librock_uint32_t m_oFreeList; struct freelist_s { librock_uint32_t offset; librock_uint32_t cb; } m_freelist[32]; int m_bFreeListLoaded; /* Derived class should set this to 0 at same time set m_oFreeList */ librock_CFsil *pfsilFree; virtual void FreeInsert(librock_uint32_t offset,librock_uint32_t cb); int m_bSplitJoin; /* Controls whether blocks will be checked to be merged and split when looking for free blocks. This should only be true if the next highest allocation offset is exactly count + sizeof(librock_uint32_t) higher (i.e. no space in between allocations) */ protected: /* Scan for free blocks */ /* If there is permanent storage, then set m_oFreeScan to the first block, and NextBlock() in the derived class will be used to iterate blocks during the calls to Alloc(). For other notes, see the comments at the body of FreeScan(). */ librock_uint32_t m_oFreeScan; librock_uint32_t FreeScan(librock_uint32_t cb); virtual librock_uint32_t NextBlock(librock_uint32_t offset,librock_uint32_t cb) = 0; virtual librock_uint32_t CheckFreed(librock_uint32_t cb); protected: /* Primitives. Each block has a control header. In the case of allocated blocks, or blocks on the m_freelist, the control header has the size of the block, a librock_uint32_t stored at (offset - sizeof(librock_uint32_t)). In the case of free'd blocks, ((librock_uint32_t) -1) is stored at (offset - sizeof(librock_uint32_t)), followed by the size of the block. This requires 2 * sizeof(librock_uint32_t) minimum for each block, with sizeof(librock_uint32_t) overhead. */ virtual void ReadCtl(librock_uint32_t offset,struct freelist_s *pscan); virtual void WriteCtl(librock_uint32_t offset,struct freelist_s *pscan); virtual librock_uint32_t Extend(librock_uint32_t cb) = 0; public: #if 0 void Dump(); void DumpScan(FILE *f); #endif librock_CAllocOffset32(); virtual ~librock_CAllocOffset32(); virtual const char * /* ERR EXPLAIN */ Alloc(librock_uint32_t cb,librock_uint32_t *pcbOffset); virtual librock_uint32_t AllocCopy(const char *p,librock_uint32_t cb); virtual const char * /* ERR EXPLAIN */ Free(librock_uint32_t offset); virtual librock_uint32_t ReadAt(librock_uint32_t offset,char *pBuf,librock_uint32_t cbBuf) = 0; virtual librock_uint32_t WriteAt(librock_uint32_t offset,const char *pBuf,librock_uint32_t cbBuf) = 0; }; /**************************************************************/ #endif #endif