virtualalloc

Benefits of reserving vs. committing+reserving memory using VirtualAlloc on large arrays

。_饼干妹妹 提交于 2019-12-22 08:19:37
问题 I am writing a C++ program that essentially works with very large arrays. On Windows, I am using VirtualAlloc to allocate memory to my arrays. Now I fully understand the difference between reserving and committing memory using VirutalAlloc; however, I am wondering whether there is any benefit in committing memory page-by-page to a reserved region. In particular, MSDN (http://msdn.microsoft.com/en-us/library/windows/desktop/aa366887(v=vs.85).aspx) contains the following explanation for the MEM

Immediate detection of heap corruption errors on Windows. How?

ぐ巨炮叔叔 提交于 2019-12-18 03:57:17
问题 I can't sleep! :) I have a reasonably large project on Windows and encountered some heap corruption issues. I have read all SO, including this nice topic: How to debug heap corruption errors?, however nothing was suitable to help me out-of-the-box. Debug CRT and BoundsChecker detected heap corruptions, but addresses were always different and detections point were always far away from the actual memory overwrites. I have not slept till the middle of the night and crafted the following hack:

Converting a pointer to a byte slice

白昼怎懂夜的黑 提交于 2019-12-08 01:38:50
问题 The Mmap() syscall in the x/sys/unix package in Golang returns a []byte type, while the underlying syscall actually returns a pointer. How does it do this? More specifically, in this package by a Golang developer, the VirtualAlloc function simply returns a pointer. How can this be converted to a byte slice, the same way as it's done in the Unix package? 回答1: Using the unsafe package you can do the same thing golang.org/x/sys/unix does in the Mmap method of its unexported mmapper type: //

Converting a pointer to a byte slice

随声附和 提交于 2019-12-06 12:44:47
The Mmap() syscall in the x/sys/unix package in Golang returns a []byte type, while the underlying syscall actually returns a pointer. How does it do this? More specifically, in this package by a Golang developer, the VirtualAlloc function simply returns a pointer. How can this be converted to a byte slice, the same way as it's done in the Unix package? Using the unsafe package you can do the same thing golang.org/x/sys/unix does in the Mmap method of its unexported mmapper type: // Slice memory layout var sl = struct { addr uintptr len int cap int }{addr, length, length} // Use unsafe to turn

Benefits of reserving vs. committing+reserving memory using VirtualAlloc on large arrays

风流意气都作罢 提交于 2019-12-05 14:24:39
I am writing a C++ program that essentially works with very large arrays. On Windows, I am using VirtualAlloc to allocate memory to my arrays. Now I fully understand the difference between reserving and committing memory using VirutalAlloc; however, I am wondering whether there is any benefit in committing memory page-by-page to a reserved region. In particular, MSDN ( http://msdn.microsoft.com/en-us/library/windows/desktop/aa366887(v=vs.85).aspx ) contains the following explanation for the MEM_COMMIT option: Actual physical pages are not allocated unless/until the virtual addresses are

For what do I need to use VirtualAlloc/VirtualAllocEx?

*爱你&永不变心* 提交于 2019-12-04 13:38:05
问题 For what do I need to use VirtualAlloc/VirtualAllocEx? An example, one case that I found - if I allocated 4 GB of virtual memory, then if I do not use all of them, then I do not spend physical memory, and if I resize my array, I do not need to do new allocating and copying old data to new array. struct T_custom_allocator; // which using VirtualAllocEx() std::vector<int, T_custom_allocator> vec; vec.reserve(4*1024*1024*1024); // allocated virtual memory (physical memory is not used) vec.resize

For what do I need to use VirtualAlloc/VirtualAllocEx?

青春壹個敷衍的年華 提交于 2019-12-03 08:37:26
For what do I need to use VirtualAlloc/VirtualAllocEx? An example, one case that I found - if I allocated 4 GB of virtual memory, then if I do not use all of them, then I do not spend physical memory, and if I resize my array, I do not need to do new allocating and copying old data to new array. struct T_custom_allocator; // which using VirtualAllocEx() std::vector<int, T_custom_allocator> vec; vec.reserve(4*1024*1024*1024); // allocated virtual memory (physical memory is not used) vec.resize(16384); // allocated 16KB of physical memory // ... vec.resize(32768); // allocated 32KB of physical

VirtualAlloc MEM_COMMIT and MEM_RESERVE

心已入冬 提交于 2019-12-01 18:33:30
I'm little confuse about VirtualAlloc, We can reserve memory use MEM_RESERVE, and then commit it use MEM_COMMIT, but I'm little confuse about what the difference when use between below two functions: m_pvData = VirtualAlloc(NULL, m_nBuffSize, MEM_COMMIT, PAGE_READWRITE); m_pvData = VirtualAlloc(NULL, m_nBuffSize, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); What‘s the benfit of the second choose? And I can use below function to get buffer: void* pdata = VirtualAlloc(NULL, 64*1024*1024, MEM_COMMIT, PAGE_READWRITE); if (pdata == NULL) { cout<<"Last error is "<<GetLastError()<<endl; } There is no

VirtualAlloc MEM_COMMIT and MEM_RESERVE

爱⌒轻易说出口 提交于 2019-12-01 18:00:55
问题 I'm little confuse about VirtualAlloc, We can reserve memory use MEM_RESERVE, and then commit it use MEM_COMMIT, but I'm little confuse about what the difference when use between below two functions: m_pvData = VirtualAlloc(NULL, m_nBuffSize, MEM_COMMIT, PAGE_READWRITE); m_pvData = VirtualAlloc(NULL, m_nBuffSize, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); What‘s the benfit of the second choose? And I can use below function to get buffer: void* pdata = VirtualAlloc(NULL, 64*1024*1024, MEM

Immediate detection of heap corruption errors on Windows. How?

非 Y 不嫁゛ 提交于 2019-11-29 03:36:31
I can't sleep! :) I have a reasonably large project on Windows and encountered some heap corruption issues. I have read all SO, including this nice topic: How to debug heap corruption errors? , however nothing was suitable to help me out-of-the-box. Debug CRT and BoundsChecker detected heap corruptions, but addresses were always different and detections point were always far away from the actual memory overwrites. I have not slept till the middle of the night and crafted the following hack: DWORD PageSize = 0; inline void SetPageSize() { if ( !PageSize ) { SYSTEM_INFO sysInfo; GetSystemInfo(