本文整理汇总了C++中VirtualLock函数的典型用法代码示例。如果您正苦于以下问题:C++ VirtualLock函数的具体用法?C++ VirtualLock怎么用?C++ VirtualLock使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了VirtualLock函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Test_VirtualAlloc
bool Test_VirtualAlloc()
{
size_t memsize = 2 * 1024 * 1024;
SIZE_T min = 0, max = 0;
::GetProcessWorkingSetSize(::GetCurrentProcess(), &min, &max);
printf("min: %u KB, max: %u KB\n", min/1024, max/1024);
{
BYTE *pBuf = (BYTE*)VirtualAlloc(NULL, memsize, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
printf("VirtualAlloc: %p\n", pBuf);
BOOL ret = VirtualLock(pBuf, memsize);
printf("VirtualLock: %d\n", ret);
memset(pBuf, 0, memsize);
// getchar();
void *pa[10];
for (int i = 0; i < 10; i++) {
pa[i] = malloc(10 * 1024 * 1024);
memset(pa[i], 0, 10 * 1024 * 1024);
}
getchar();
for (int i = 0; i < 10; i++) {
free(pa[i]);
}
if (ret) VirtualUnlock(pBuf, memsize);
VirtualFree(pBuf, memsize, 0);
}
min += 2 * 1024 * 1024;
max += 2 * 1024 * 1024;
::SetProcessWorkingSetSize(::GetCurrentProcess(), min, max);
printf("min: %u KB, max: %u KB\n", min / 1024, max / 1024);
{
BYTE *pBuf = (BYTE*)VirtualAlloc(NULL, memsize, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
printf("VirtualAlloc: %p\n", pBuf);
BOOL ret = VirtualLock(pBuf, memsize);
printf("VirtualLock: %d\n", ret);
memset(pBuf, 0, memsize);
// getchar();
if (ret) VirtualUnlock(pBuf, memsize);
VirtualFree(pBuf, memsize, 0);
}
return 0;
}
示例2: l
char* disk_buffer_pool::allocate_buffer(char const* category)
{
mutex::scoped_lock l(m_pool_mutex);
TORRENT_ASSERT(m_magic == 0x1337);
#ifdef TORRENT_DISABLE_POOL_ALLOCATOR
char* ret = page_aligned_allocator::malloc(m_block_size);
#else
char* ret = (char*)m_pool.ordered_malloc();
m_pool.set_next_size(m_settings.cache_buffer_chunk_size);
#endif
++m_in_use;
#if TORRENT_USE_MLOCK
if (m_settings.lock_disk_cache)
{
#ifdef TORRENT_WINDOWS
VirtualLock(ret, m_block_size);
#else
mlock(ret, m_block_size);
#endif
}
#endif
#if defined TORRENT_DISK_STATS || defined TORRENT_STATS
++m_allocations;
#endif
#ifdef TORRENT_DISK_STATS
++m_categories[category];
m_buf_to_category[ret] = category;
m_log << log_time() << " " << category << ": " << m_categories[category] << "\n";
#endif
TORRENT_ASSERT(ret == 0 || is_disk_buffer(ret, l));
return ret;
}
示例3: lockMemory
static void lockMemory( INOUT MEM_INFO_HEADER *memHdrPtr )
{
assert( isWritePtr( memHdrPtr, sizeof( MEM_INFO_HEADER ) ) );
if( VirtualLock( ( void * ) memHdrPtr, memHdrPtr->size ) )
memHdrPtr->flags |= MEM_FLAG_LOCKED;
}
示例4: crypto_open
PCRYPTO_INFO crypto_open ()
{
#ifndef GST_WINDOWS_BOOT
/* Do the crt allocation */
PCRYPTO_INFO cryptoInfo = (PCRYPTO_INFO) GSTalloc (sizeof (CRYPTO_INFO));
if (cryptoInfo == NULL)
return NULL;
memset (cryptoInfo, 0, sizeof (CRYPTO_INFO));
#ifndef DEVICE_DRIVER
VirtualLock (cryptoInfo, sizeof (CRYPTO_INFO));
#endif
cryptoInfo->ea = -1;
return cryptoInfo;
#else // GST_WINDOWS_BOOT
#if 0
if (CryptoInfoBufferInUse)
GST_THROW_FATAL_EXCEPTION;
#endif
CryptoInfoBufferInUse = 1;
return &CryptoInfoBuffer;
#endif // GST_WINDOWS_BOOT
}
示例5: MemAllocLocked
PTR MemAllocLocked( UINT32 uiSize )
{
PTR ptr;
if ( !fMemManagerInit )
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("MemAllocLocked: Warning -- Memory manager not initialized!!! ") );
ptr = VirtualAlloc( NULL, uiSize, MEM_COMMIT, PAGE_READWRITE );
if ( ptr )
{
VirtualLock( ptr, uiSize );
guiMemTotal += uiSize;
guiMemAlloced += uiSize;
MemDebugCounter++;
}
else
{
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_0, String("MemAllocLocked failed: %d bytes", uiSize) );
}
#ifdef DEBUG_MEM_LEAKS
DbgMessage( TOPIC_MEMORY_MANAGER, DBG_LEVEL_1, String("MemAllocLocked %p: %d bytes", ptr, uiSize) );
#endif
return( ptr );
}
示例6: My_VirtualLock
BOOL My_VirtualLock()
{
LPVOID lpAddress=NULL;
SIZE_T dwSize=NULL;
BOOL returnVal_Real = NULL;
BOOL returnVal_Intercepted = NULL;
DWORD error_Real = 0;
DWORD error_Intercepted = 0;
disableInterception();
returnVal_Real = VirtualLock (lpAddress,dwSize);
error_Real = GetLastError();
enableInterception();
returnVal_Intercepted = VirtualLock (lpAddress,dwSize);
error_Intercepted = GetLastError();
return ((returnVal_Real == returnVal_Intercepted) && (error_Real == error_Intercepted));
}
示例7: VirtualLock
bool MemoryPageLocker::Lock(const void* addr, size_t len)
{
#ifdef WIN32
return VirtualLock(const_cast<void*>(addr), len) != 0;
#else
return mlock(addr, len) == 0;
#endif
}
示例8: Randinit
/* Init the random number generator, setup the hooks, and start the thread */
int Randinit ()
{
DWORD dwLastError = ERROR_SUCCESS;
if (GetMaxPkcs5OutSize() > RNG_POOL_SIZE)
TC_THROW_FATAL_EXCEPTION;
if(bRandDidInit)
return 0;
InitializeCriticalSection (&critRandProt);
bRandDidInit = TRUE;
CryptoAPILastError = ERROR_SUCCESS;
ProcessedMouseEventsCounter = 0;
if (pRandPool == NULL)
{
pRandPool = (unsigned char *) TCalloc (RANDOMPOOL_ALLOCSIZE);
if (pRandPool == NULL)
goto error;
bDidSlowPoll = FALSE;
RandomPoolEnrichedByUser = FALSE;
memset (pRandPool, 0, RANDOMPOOL_ALLOCSIZE);
VirtualLock (pRandPool, RANDOMPOOL_ALLOCSIZE);
}
hKeyboard = SetWindowsHookEx (WH_KEYBOARD, (HOOKPROC)&KeyboardProc, NULL, GetCurrentThreadId ());
if (hKeyboard == 0) handleWin32Error (0, SRC_POS);
hMouse = SetWindowsHookEx (WH_MOUSE, (HOOKPROC)&MouseProc, NULL, GetCurrentThreadId ());
if (hMouse == 0)
{
handleWin32Error (0, SRC_POS);
goto error;
}
if (!CryptAcquireContext (&hCryptProv, NULL, MS_ENHANCED_PROV, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_SILENT))
{
CryptoAPIAvailable = FALSE;
CryptoAPILastError = GetLastError ();
goto error;
}
else
CryptoAPIAvailable = TRUE;
if (!(PeriodicFastPollThreadHandle = (HANDLE) _beginthreadex (NULL, 0, PeriodicFastPollThreadProc, NULL, 0, NULL)))
goto error;
return 0;
error:
dwLastError = GetLastError();
RandStop (TRUE);
SetLastError (dwLastError);
return 1;
}
示例9: mlock
int mlock(const void *addr, size_t len)
{
if (VirtualLock((LPVOID)addr, len))
return 0;
errno = __map_mman_error(GetLastError(), EPERM);
return -1;
}
示例10: lockPage
bool lockPage(void* addr, int len){
#if defined(Q_WS_X11) || defined(Q_WS_MAC)
return (mlock(addr, len)==0);
#elif defined(Q_WS_WIN)
return VirtualLock(addr, len);
#else
return false;
#endif
}
示例11: mlock
int
mlock(const void *addr, size_t len)
{
if (VirtualLock((LPVOID)addr, len))
return 0;
errno = EBADF;
return -1;
}
示例12: salloc
// Allocate memory
void* salloc(size_t len)
{
#ifdef SENSITIVE_NON_PAGED
// Allocate memory on a page boundary
#ifndef _WIN32
void* ptr = (void*) valloc(len);
#else
pointer r = (pointer) VirtualAlloc(NULL, n * sizeof(T), MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
#endif
if (ptr == NULL)
{
ERROR_MSG("Out of memory");
return NULL;
}
// Lock the memory so it doesn't get swapped out
#ifndef _WIN32
if (mlock((const void*) ptr, len) != 0)
#else
if (VirtualLock((const void*) r, n * sizeof(T)) == 0)
#endif
{
ERROR_MSG("Could not allocate non-paged memory for secure storage");
// Hmmm... best to not return any allocated space in this case
#ifndef _WIN32
free(ptr);
#else
VirtualFree((const void*) pre, MEM_RELEASE);
#endif
return NULL;
}
// Register the memory in the secure memory registry
SecureMemoryRegistry::i()->add(ptr, len);
return ptr;
#else
void* ptr = (void*) malloc(len);
if (ptr == NULL)
{
ERROR_MSG("Out of memory");
return NULL;
}
// Register the memory in the secure memory registry
SecureMemoryRegistry::i()->add(ptr, len);
return ptr;
#endif // SENSITIVE_NON_PAGED
}
示例13: mlock
int mlock(const void *addr, size_t len)
{
if (VirtualLock((LPVOID)addr, len))
return 0;
else
{
errno = windowsErrorToErrno(GetLastError());
return -1;
}
}
示例14: mlock
int mlock(const void* addr, size_t len)
{
if (VirtualLock((LPVOID)addr, len) != FALSE)
{
errno = 0;
return 0;
}
errno = last_error(EPERM);
return -1;
}
示例15: inmem_malloc
void* inmem_malloc(size_t size)
{
void *ptr = malloc(size);
if (ptr == NULL)
{
printf("inmem_malloc failed!\n");
exit(1);
}
VirtualLock(ptr, size);
return ptr;
}