/* librock/allocom.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_MD5=f2a00374df769e694451262ac9df1336 */ #ifndef librock_INCLUDE_ALLOCOM_H #define librock_INCLUDE_ALLOCOM_H #ifdef librock_EXPERIMENTAL #ifndef librock_ISOLATED #include #endif #ifdef __cplusplus #include class librock_CAllocOffsetMEM : public librock_CAllocOffset32 { protected: public: /* Primitives */ virtual librock_uint32_t ReadAt(librock_uint32_t offset,char *pBuf,librock_uint32_t cbBuf); virtual librock_uint32_t WriteAt(librock_uint32_t offset,const char *pBuf,librock_uint32_t cbBuf); virtual librock_uint32_t NextBlock(librock_uint32_t offset,librock_uint32_t cb); /* DEBUG: pooled allocations would make it easier to clean up */ virtual librock_uint32_t Extend(librock_uint32_t cb) { librock_uint32_t l = (librock_uint32_t) malloc(cb); fprintf(stderr,"Extend = [%ld+%ld]\n",l,cb); struct freelist_s e; l +=sizeof(librock_uint32_t); e.offset = l; e.cb = cb; WriteCtl(l,&e); return l; }; public: librock_CAllocOffsetMEM() { m_bSplitJoin = 0; }; virtual ~librock_CAllocOffsetMEM() { /* Free everything on pfsilFree */ long i = 0; while(i < pfsilFree->count()) { struct freelist_s *p; p = (struct freelist_s *) pfsilFree->PtrAt(i); if (!p) { break; } free((void *) (p->offset-sizeof(librock_uint32_t))); i++; } }; }; /**************************************************************/ #endif #endif #endif