diff options
author | Adam <you@example.com> | 2020-05-17 05:51:50 +0200 |
---|---|---|
committer | Adam <you@example.com> | 2020-05-17 05:51:50 +0200 |
commit | e611b132f9b8abe35b362e5870b74bce94a1e58e (patch) | |
tree | a5781d2ec0e085eeca33cf350cf878f2efea6fe5 /private/unimodem/new/mic/alloc.h | |
download | NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.gz NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.bz2 NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.lz NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.xz NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.zst NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.zip |
Diffstat (limited to 'private/unimodem/new/mic/alloc.h')
-rw-r--r-- | private/unimodem/new/mic/alloc.h | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/private/unimodem/new/mic/alloc.h b/private/unimodem/new/mic/alloc.h new file mode 100644 index 000000000..ae5637608 --- /dev/null +++ b/private/unimodem/new/mic/alloc.h @@ -0,0 +1,86 @@ +// +// Copyright (c) 1996 Microsoft Corporation +// +// +// ALLOC.H -- Header for Classes: +// CAllococator +// +// +// History: +// 05/22/96 JosephJ Created +// +// +#if (TODO) + + +class CAllocator +{ + Allocator(UINT uSize) : m_uSize(uSize) + { + ASSERT(!(uSize %sizeof(void *))); + m_uBlockSize = (uSize+sizeof(void *)) + if (uSize<1000) + m_uBlockSize = m_uBlockSize*10 + sizeof(void *) + + m_uBlockSize += sizeof (void*); + } + + ~Allocator() + { + void *pList = m_pBlockList; + while(pList) + { + void *pOld = pList; + pList = (void *) *pList; + GlobalFree(pOld); + } + } + + void * Alloc(void) + { + m_sync.EnterCrit(); + + void *pvRet = m_pFreeList; + + if (!m_pFreeList) + { + void *pv = GlobalAlloc(LPTR, m_uBlockSize); + void *pvEnd = pv+m_uBlockSize; + if (pv) + { + *pv = m_pvBlockList; + m_pvBlockList = pv; + m_pFreeList = ++pv; + for(;;pv = *pv) + { + *pv = pv + m_uSize + sizeof (void *); + if (*pv >= pvEnd) {*pv=NULL;break;} + pv = *pv; + } + pvRet = m_pFreeList; + } + } + + m_sync.LeaveCrit(); + + return pvRet; + } + + void Free(void *pv) + { + m_sync.EnterCrit(); + pv--; + *pv = m_pFreeList; + m_pFreeList=*pv; + m_sync.LeaveCrit(); + } + +private: + + void * m_pFreeList; + void * m_pBlockList; + const UINT m_uSize; + UINT m_uBlockSize; + CSync m_sync; +} +#endif (TODO) |