本文整理汇总了C++中HeapCreate函数的典型用法代码示例。如果您正苦于以下问题:C++ HeapCreate函数的具体用法?C++ HeapCreate怎么用?C++ HeapCreate使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了HeapCreate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _tmain
int _tmain(int argc, _TCHAR* argv[])
{
HANDLE hHeap = HeapCreate(HEAP_NO_SERIALIZE, PAGE_SIZE*10, PAGE_SIZE*100);
int* pArr = (int* ) HeapAlloc(hHeap, 0, sizeof(int) * 30);
for(int i = 0 ; i < 10 ; ++i)
{
if(i % 5 == 0)
printf_s("\n");
pArr[i] = (i + 1) * 100;
}
for(int i = 0 ; i < 30 ; ++i)
{
if(i % 5 == 0)
printf_s("\n");
printf_s("%d ", pArr[i]);
}
HeapFree(hHeap, 0, pArr);
HeapDestroy(hHeap);
getchar();
return 0;
}
示例2: main
int main(int argc, char *argv[]){
void *test;
HGLOBAL hgtest;
HLOCAL hltest;
HANDLE heapcreate;
LPVOID hptest;
//LPVOID hvtest;
test = malloc(100);
memset(test,'a',100);
zfree(test);
hgtest = GlobalAlloc(GMEM_FIXED,100);
memset(hgtest,'a',100);
zGlobalFree(hgtest);
hltest = LocalAlloc(LMEM_FIXED,100);
memset(hltest,'a',100);
zLocalFree(hltest);
heapcreate = HeapCreate(0,100,100);
hptest = HeapAlloc(heapcreate,HEAP_ZERO_MEMORY,100);
memset(hptest,'a',100);
zHeapFree(heapcreate,0,hptest);
HeapDestroy(heapcreate);
/* yet to implement
hvtest = VirtualAlloc(NULL,100,MEM_COMMIT,PAGE_READWRITE);
memset(hvtest,'a',100);
zVirtualFree(hvtest,100,MEM_RELEASE);
return 0;
*/
}
示例3: HeapCreate
BOOL
LongBinary::SetBinarySize(DWORD sizeNew, void* lpDataCopy){
if (m_hMemory == NULL){ // Allocate
m_pBuffer = NULL;
if (sizeNew == 0)
return TRUE;
m_hMemory = HeapCreate(0L, sizeNew, 0L);
ASSERT(m_hMemory);
m_pBuffer = HeapAlloc(m_hMemory, 0L, sizeNew);
m_dwSize = sizeNew;
}
else{ // Reallocate
if (sizeNew > m_dwSize){
// Allocate or realocate memory . #####
m_pBuffer = HeapReAlloc(m_hMemory, 0L, m_pBuffer, sizeNew);
m_dwSize = sizeNew;
}
else
if (sizeNew == 0){
HeapFree(m_hMemory, 0L, m_pBuffer);
HeapDestroy(m_hMemory);
m_pBuffer = NULL;
m_hMemory = NULL;
m_dwSize = 0;
}
}
if( lpDataCopy != NULL && m_hMemory ){
memcpy(m_pBuffer, lpDataCopy, sizeNew);
}
return TRUE;
}
示例4: Unitialize
BOOL CHeapAllocator::Initialize(SIZE_T dwInitSize)
{
Unitialize();
m_hHeap = HeapCreate(0,dwInitSize,0);
// Jie JIAN changed @ 2007-12-28
// use LFH if possible
typedef BOOL (WINAPI *PFN_HEAPSETINFORMATION)(HANDLE, HEAP_INFORMATION_CLASS, PVOID, SIZE_T);
HMODULE hKernel32 = LoadLibraryW( L"kernel32.dll" );
if ( NULL != hKernel32 )
{
PFN_HEAPSETINFORMATION pfnHeapSetInformation =
reinterpret_cast<PFN_HEAPSETINFORMATION>(
GetProcAddress(hKernel32, "HeapSetInformation")
);
if ( NULL != pfnHeapSetInformation )
{
ULONG ulHeapInformation = 2;
(*pfnHeapSetInformation)( m_hHeap,
HeapCompatibilityInformation,
&ulHeapInformation,
sizeof(ULONG) );
}
FreeLibrary(hKernel32);
}
return TRUE;
}
示例5: ProcessAttach
// TODO: I should probably move all initalization inside the thread
// We should minimize the amount of work done in DLL_PROCESS_ATTACH as per
// http://blogs.msdn.com/b/oleglv/archive/2003/10/24/56141.aspx
static BOOL ProcessAttach()
{
lf("memtrace.dll: ProcessAttach()");
if (!OpenPipe()) {
lf("memtrace.dll: couldn't open pipe");
return FALSE;
} else {
lf("memtrace.dll: opened pipe");
}
gHeap = HeapCreate(0, 0, 0);
if (!gHeap) {
lf("memtrace.dll: failed to create heap");
return FALSE;
}
InitializeCriticalSection(&gMemMutex);
gSendThreadEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
if (!gSendThreadEvent) {
lf("memtrace.dll: couldn't create gSendThreadEvent");
return FALSE;
}
gSendThread = CreateThread(NULL, 0, DataSendThreadProc, NULL, 0, 0);
if (!gSendThread) {
lf("memtrace.dll: couldn't create gSendThread");
return FALSE;
}
InstallHooks();
return TRUE;
}
示例6: tb_native_memory_init
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
tb_bool_t tb_native_memory_init()
{
// enter
tb_spinlock_enter_without_profiler(&g_lock);
// done
tb_bool_t ok = tb_false;
do
{
// have been inited?
tb_check_break_state(!g_heap, ok, tb_true);
// make heap
g_heap = (tb_handle_t)HeapCreate(0, 0, 0);
tb_check_break(g_heap);
// ok
ok = tb_true;
} while (0);
// leave
tb_spinlock_leave(&g_lock);
// ok?
return ok;
}
示例7: _win32_initHeap
inline static void _win32_initHeap( void )
{
g_privateHeap = HeapCreate( 0, 0, 0 );
unsigned int info = 0;
HeapSetInformation( g_privateHeap, HeapCompatibilityInformation, &info, sizeof(info) );
}
示例8: PatchMW2_StringList
void PatchMW2_StringList()
{
slHashMap.set_empty_key("*DUMMYDUMMY*");
slHashMap.set_deleted_key("*DUMMYDUMM*");
call(0x4D2280, SL_Init, PATCH_JUMP);
call(0x436B40, SL_GetStringOfSize, PATCH_JUMP);
call(0x4EC1D0, SL_ConvertToString_, PATCH_JUMP);
call(0x61BCB0, FindStringOfSize, PATCH_JUMP);
call(0x469D80, SL_ConvertFromString, PATCH_JUMP);
call(0x4D9B00, SL_AddRefToString, PATCH_JUMP);
call(0x4F1500, SL_RemoveRefToStringOfSize, PATCH_JUMP);
call(0x47CD70, SL_RemoveRefToString, PATCH_JUMP);
call(0x417730, Scr_SetString, PATCH_JUMP);
call(0x4401E0, SL_GetStringLen, PATCH_JUMP);
call(0x40C050, SL_TransferRefToUser, PATCH_JUMP);
call(0x4B4310, SL_AddUser, PATCH_JUMP);
call(0x430510, SL_ConvertToLowercase, PATCH_JUMP);
call(0x4F46D0, SL_ShutdownSystem, PATCH_JUMP);
call(0x4A44A0, SL_TransferSystem, PATCH_JUMP);
stringHeap = HeapCreate(0, 1024 * 1024, 0);
// path_node_constant_t marking function; has some terrible string references
*(BYTE*)0x4F74B0 = 0xC3;
}
示例9: hpgs_init
/*! This function has to be called before using any other
function of hpgs. It defines the path, where additional
files such as the truetype files for HPGL files or plugins
are stored.
Truetype fonts are searched in the path <prefix>/share/hpgs
The path is internally duplicated using \c strdup.
*/
void hpgs_init(const char *path)
{
int l;
hpgs_reader_prefix = strdup(path);
if (!hpgs_reader_prefix) return;
// strip off trailing directory separators.
l = strlen(hpgs_reader_prefix);
if (l && hpgs_reader_prefix[l-1] == HPGS_PATH_SEPARATOR)
hpgs_reader_prefix[l-1] = '\0';
#ifdef WIN32
hHeap = HeapCreate(0,4096,128*1024);
tls_handle = TlsAlloc();
#else
pthread_key_create (&key,free);
#endif
#ifdef HPGS_HAVE_GETTEXT
hpgs_i18n_init();
#endif
hpgs_font_init();
}
示例10: m_heap
CLrpHeap::CLrpHeap() : m_heap(HeapCreate(0, 0, 0))
{
if (nullptr == m_heap)
{
throw runtime_error("Couldn't create a new memory heap");
}
}
示例11: MH_Initialize
//-------------------------------------------------------------------------
MH_STATUS WINAPI MH_Initialize(VOID)
{
MH_STATUS status = MH_OK;
EnterSpinLock();
if (g_hHeap == NULL)
{
g_hHeap = HeapCreate(0, 0, 0);
if (g_hHeap != NULL)
{
// Initialize the internal function buffer.
InitializeBuffer();
}
else
{
status = MH_ERROR_MEMORY_ALLOC;
}
}
else
{
status = MH_ERROR_ALREADY_INITIALIZED;
}
LeaveSpinLock();
return status;
}
示例12: get_tls_heap
HANDLE get_tls_heap()
{
if (local_heap_tls == 0)
{
local_heap_tls = TlsAlloc();
if (local_heap_tls == 0)
{
return (NULL);
}
}
void* tls_val = TlsGetValue(local_heap_tls);
if (tls_val == NULL)
{
HANDLE heap = HeapCreate(HEAP_NO_SERIALIZE, 0, 0);
if (heap == 0)
{
return (NULL);
}
tls_val = (void*)heap;
TlsSetValue(local_heap_tls, tls_val);
}
return (HANDLE)tls_val;
}
示例13: InitModuleNames
int InitModuleNames(void)
{
struct DBModuleName *dbmn;
DWORD ofsThis;
int nameLen;
char *mod;
hModHeap=HeapCreate(0,0,0);
lMods.sortFunc=ModCompare;
lMods.increment=50;
lOfs.sortFunc=OfsCompare;
lOfs.increment=50;
ofsThis=dbHeader.ofsFirstModuleName;
dbmn=(struct DBModuleName*)DBRead(ofsThis,sizeof(struct DBModuleName),NULL);
while(ofsThis) {
if(dbmn->signature!=DBMODULENAME_SIGNATURE) DatabaseCorruption(NULL);
nameLen=dbmn->cbName;
mod = (char*)HeapAlloc(hModHeap,0,nameLen+1);
CopyMemory(mod,DBRead(ofsThis+offsetof(struct DBModuleName,name),nameLen,NULL),nameLen);
mod[nameLen] = 0;
AddToList(mod, nameLen, ofsThis);
ofsThis=dbmn->ofsNext;
dbmn=(struct DBModuleName*)DBRead(ofsThis,sizeof(struct DBModuleName),NULL);
}
CreateServiceFunction(MS_DB_MODULES_ENUM,EnumModuleNames);
return 0;
}
示例14: WinAPIOverride32Init
BOOL WinAPIOverride32Init(HINSTANCE hInst) {
TCHAR psz[MAX_PATH+32];
TCHAR pszPID[32];
SYSTEM_INFO siSysInfo;
DisableThreadLibraryCalls(hInst);
dwCurrentProcessID = GetCurrentProcessId();
wsprintf(pszPID, "0x%X", dwCurrentProcessID);
lstrcpy(psz, APIOVERRIDE_MUTEX);
lstrcat(psz, pszPID);
pSingleInstance = new CSingleInstance(psz);
if (pSingleInstance->IsAnotherInstanceRunning()) {
delete pSingleInstance;
return FALSE;
}
GetSystemInfo(&siSysInfo);
dwSystemPageSize = siSysInfo.dwPageSize;
ApiOverrideHeap = HeapCreate(HEAP_CREATE_ENABLE_EXECUTE | HEAP_GROWABLE, dwSystemPageSize, 0);
pLinkListAPIInfos = new CLinkList(sizeof(API_INFO));
pLinkListAPIInfos->SetHeap(ApiOverrideHeap);
return TRUE;
}
示例15: CreateMutex
Thunk32Base::Thunk32Base()
{
// Double checked locking, guaranteed by Acquire/Release-semantics in Microsoft's
// volatile-implementation.
if(bytecodeHeap == NULL)
{
hMutex = CreateMutex(NULL, TRUE, NULL);
while (hMutex == (HANDLE)NULL || hMutex == (HANDLE)ERROR_ALREADY_EXISTS || hMutex == (HANDLE)ERROR_ACCESS_DENIED) {
Sleep(1000);
}
if(bytecodeHeap == NULL)
{
bytecodeHeap = HeapCreate(HEAP_CREATE_ENABLE_EXECUTE, 0, 0);
if(bytecodeHeap == NULL)
{
throw std::exception("Heap creation failed!");
}
// Schedule the heap to be destroyed when the application terminates.
// Until then, it will manage its own size.
atexit(cleanupHeap);
}
}
bytecode = reinterpret_cast<Bytecode*>(HeapAlloc(bytecodeHeap, 0, sizeof(Bytecode)));
if(bytecode == NULL)
{
throw std::exception("Bytecode allocation failed!");
}
new (bytecode) Bytecode;
}