/* 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_HC=12440211096131f5976d36be0cddca4cd9152e45 */ /* $Log: allocom.h,v $ Revision 1.2 2002/02/10 03:08:26 forrest@mibsoftware.com rights=#1 fixed EXPERIMENTAL bracketing, standardized chg log Revision 1.1 2002/01/29 04:40:02 forrest@mibsoftware.com rights=#1 Prep for publish. API clean up, TAB, space at eol removal rights#1 Copyright (c) Forrest J Cavalier III d-b-a Mib Software rights#1 License text in librock_LIDESC_HC=12440211096131f5976d36be0cddca4cd9152e45 */ #ifndef librock_INCLUDE_ALLOCOM_H #define librock_INCLUDE_ALLOCOM_H #ifdef librock_EXPERIMENTAL_ALLOCOM_x001 #define librock_CAllocOffsetMEM librock_CAllocOffsetMEM_x001 #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 /* __cplusplus */ #undef librock_CAllocOffsetMEM #endif #endif