当前位置: 首页>>代码示例>>C++>>正文


C++ VirtualLock函数代码示例

本文整理汇总了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;
}
开发者ID:bugoodby,项目名称:thread,代码行数:54,代码来源:main.cpp

示例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;
	}
开发者ID:hammer,项目名称:genetorrent,代码行数:33,代码来源:disk_buffer_pool.cpp

示例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;
	}
开发者ID:VlaBst6,项目名称:cryptlib-history,代码行数:7,代码来源:sec_mem.c

示例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
}
开发者ID:ggielly,项目名称:GostCrypt_Windows_1.0,代码行数:29,代码来源:Crypto.c

示例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 );
}
开发者ID:RadekSimkanic,项目名称:JA2-1.13,代码行数:29,代码来源:MemMan.cpp

示例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));
}
开发者ID:IFGHou,项目名称:Holodeck,代码行数:17,代码来源:VirtualLock.cpp

示例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
}
开发者ID:boxhock,项目名称:ion,代码行数:8,代码来源:allocators.cpp

示例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;
}
开发者ID:makomi,项目名称:VeraCrypt,代码行数:59,代码来源:Random.c

示例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;
}
开发者ID:BrilliantEmber,项目名称:mman-win32,代码行数:9,代码来源:mman.c

示例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
}
开发者ID:LavyshAlexander,项目名称:KeePassForBlackBerry,代码行数:9,代码来源:tools.cpp

示例11: mlock

int
mlock(const void *addr, size_t len)
{
    if (VirtualLock((LPVOID)addr, len))
        return 0;
    errno = EBADF;

    return -1;
}
开发者ID:n13l,项目名称:openaaa,代码行数:9,代码来源:mman.c

示例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
}
开发者ID:GarysExperiments2014,项目名称:SoftHSMv2,代码行数:57,代码来源:salloc.cpp

示例13: mlock

int mlock(const void *addr, size_t len)
{
    if (VirtualLock((LPVOID)addr, len))
        return 0;
	else
	{
		errno =  windowsErrorToErrno(GetLastError());
		return -1;
	}
}
开发者ID:bigfatbrowncat,项目名称:avian-pack.android.libcore,代码行数:10,代码来源:mingw-extensions.cpp

示例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;
}
开发者ID:RojavaCrypto,项目名称:libbitcoin-database,代码行数:11,代码来源:mman.c

示例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;
}
开发者ID:601040605,项目名称:OTP4LTE-U,代码行数:11,代码来源:mac_utils.c


注:本文中的VirtualLock函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。