uLib  User mode C/C++ extended API library for Win32 programmers.
MemFunc.h
Go to the documentation of this file.
1 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 // Project: uLib - User mode utility library.
3 // Module: Shared memory and solid heap allocation routines.
4 // Author: Copyright (c) Love Nystrom
5 // License: NNOSL (BSD descendant, see NNOSL.txt in the base directory).
6 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 
8 #ifndef _Memo_h_incl_
9 #define _Memo_h_incl_
10 
11 #include <uLib/Common.h>
12 
21 
23 
28 
29 extern HANDLE app_Heap;
30 
37 
38 void* mem_Alloc( size_t Bytes );
39 
47 
48 void* mem_Realloc( void* pBlk, size_t Bytes );
49 
54 
55 void* mem_Free( void* pBlk );
56 
59 
60 bool mem_Compact();
61 
63 
64 #ifdef __cplusplus
65 #ifdef USE_ULIB_NEW_DELETE
67 
68 
70 _inline void* operator new( size_t Bytes ) { return mem_Alloc( Bytes ); }
71 _inline void* operator new[]( size_t Bytes ) { return mem_Alloc( Bytes ); }
72 
74 
75 _inline void* operator new( size_t Bytes, void* pBlk ) { return mem_Realloc( pBlk, Bytes ); }
76 _inline void* operator new[]( size_t Bytes, void* pBlk ) { return mem_Realloc( pBlk, Bytes ); }
77 
78 _inline void operator delete( void* pBlk ) { mem_Free( pBlk ); }
79 _inline void operator delete[]( void* pBlk ) { mem_Free( pBlk ); }
80 
81 _inline void operator delete( void* pBlk, void* plc ) { mem_Free( pBlk ); }
82 _inline void operator delete[]( void* pBlk, void* plc ) { mem_Free( pBlk ); }
83 
85 #endif // USE_ULIB_NEW_DELETE
86 #endif //__cplusplus
87 
88 //==---------------------------------------------------------------------------
97 //==---------------------------------------------------------------------------
100 
105 
106 PVOID AllocMemoryPages( WORD nPages, DWORD Access DEF_(PAGE_READWRITE) );
107 
110 
111 PVOID FreeMemoryPages( PVOID pBlk );
112 
116 
118 
122 
123 UINT GetPageRegionSize( PVOID pBlk );
124 
128 
129 PVOID GetPageBaseAddress( PVOID pBlk );
130 
134 
135 PVOID GetPageAllocationBase( PVOID pBlk );
136 
139 //==---------------------------------------------------------------------------
152 //==---------------------------------------------------------------------------
155 
156 DECLARE_HANDLE( HPHYSICAL );
157 #define PHYSICAL_PTR( hmem ) (*(PVOID*)hmem)
158 
159 
169 HPHYSICAL PhysicalAlloc( UINT64 nBytes );
170 
174 
176 
179 
180 PVOID PhysicalPtr( HPHYSICAL hMem );
181 
184 
186 
189 
190 ULONG_PTR PhysicalPageCount( HPHYSICAL hMem );
191 
194 #ifdef __cplusplus
195 //-----------------------------------------------------------------------------
197 //-----------------------------------------------------------------------------
202 //-----------------------------------------------------------------------------
203 
204 class SharedMem {
205 public:
206  PVOID const& pData;
207 
208  operator PVOID() { return _pmem; }
209  operator TSTR() { return (TSTR)_pmem; }
210 
211  SharedMem( size_t Size, CSTR Name );
212  SharedMem( CSTR Name );
213  ~SharedMem();
214 
215  size_t Size();
216  bool Flush( PVOID Addr, size_t Range );
217 
218 protected:
220  HANDLE _hmem;
221  PVOID _pmem;
223 };
224 
225 #endif //__cplusplus
226 #endif //ndef _Memo_h_incl_
228 // EOF
unsigned long DWORD
Definition: Common.h:414
PVOID FreeMemoryPages(PVOID pBlk)
Definition: MemFunc.cpp:193
HPHYSICAL PhysicalFree(HPHYSICAL hMem)
Definition: MemFunc.cpp:428
#define CSTR
Definition: Common.h:329
unsigned short WORD
Definition: Common.h:413
DWORD GetMemoryPageSize()
Definition: MemFunc.cpp:215
void * mem_Realloc(void *pBlk, size_t Bytes)
Definition: MemFunc.cpp:80
Interprocess shared memory.
Definition: MemFunc.h:204
void * mem_Alloc(size_t Bytes)
Definition: MemFunc.cpp:33
ULONG_PTR PhysicalPageCount(HPHYSICAL hMem)
Definition: MemFunc.cpp:338
#define TSTR
Definition: Common.h:328
~SharedMem()
Definition: MemFunc.cpp:268
#define END_NAMESPACE(name)
Definition: Common.h:225
UINT GetPageRegionSize(PVOID pBlk)
Definition: MemFunc.cpp:222
PVOID GetPageBaseAddress(PVOID pBlk)
Definition: MemFunc.cpp:234
bool Flush(PVOID Addr, size_t Range)
Definition: MemFunc.cpp:289
void * mem_Free(void *pBlk)
Definition: MemFunc.cpp:124
Definition: DynArray.h:18
unsigned __int64 UINT64
Definition: Common.h:400
bool mem_Compact()
Definition: MemFunc.cpp:150
HPHYSICAL PhysicalAlloc(UINT64 nBytes)
Definition: MemFunc.cpp:344
#define BEGIN_NAMESPACE(name)
Definition: Common.h:224
#define DEF_(x)
Definition: Common.h:240
Common include; Added types, small "ubiquitous" utilities, et c.
#define END_EXTERN_C
Definition: Common.h:221
#define BEGIN_EXTERN_C
Definition: Common.h:220
size_t Size()
Definition: MemFunc.cpp:274
PVOID AllocMemoryPages(WORD nPages, DWORD Access=PAGE_READWRITE)
Definition: MemFunc.cpp:177
SharedMem(size_t Size, CSTR Name)
Definition: MemFunc.cpp:254
PVOID GetPageAllocationBase(PVOID pBlk)
Definition: MemFunc.cpp:242
HANDLE app_Heap
Definition: MemFunc.cpp:12
PVOID PhysicalPtr(HPHYSICAL hMem)
Definition: MemFunc.cpp:330
HANDLE HPHYSICAL
Definition: MemFunc.h:156
PVOID const & pData
Const pointer to variable data.
Definition: MemFunc.h:206
UINT64 PhysicalSize(HPHYSICAL hMem)
Definition: MemFunc.cpp:334