Questions tagged [virtualalloc]

64 questions
51
votes
4 answers

Any way to reserve but not commit memory in linux?

Windows has VirtualAlloc, which allows you to reserve a contiguous region of address space, but not actually use any physical memory. Later when you want to use it (or part of it) you call VirtualAlloc again to commit the region of previously…
Eloff
  • 20,828
  • 17
  • 83
  • 112
14
votes
3 answers

Immediate detection of heap corruption errors on Windows. How?

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.…
Sergey K.
  • 24,894
  • 13
  • 106
  • 174
8
votes
1 answer

VirtualAlloc MEM_COMMIT and MEM_RESERVE

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,…
user2714997
  • 81
  • 1
  • 4
7
votes
1 answer

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

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,…
user1381414
6
votes
2 answers

VirtualAlloc failing

I am trying to use VirtualAlloc to reserve and commit a block of memory and then again to extend that block. Unfortunately, it is returning NULL with error ERROR_INVALID_ADDRESS despite VirtualQuery saying that the address range requested is free.…
Falcon
  • 445
  • 3
  • 10
5
votes
3 answers

how do I copy the contents of a file into virtual memory?

I have a small file, I go over it and count the number of bytes in it: while(fgetc(myFilePtr) != EOF) { numbdrOfBytes++; } Now I allocate virtual memory of the same size: BYTE* myBuf = (BYTE*)VirtualAlloc(NULL, numbdrOfBytes, MEM_COMMIT |…
M.N
  • 333
  • 3
  • 9
5
votes
2 answers

For what do I need to use VirtualAlloc/VirtualAllocEx?

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…
Alex
  • 12,578
  • 15
  • 99
  • 195
4
votes
2 answers

How malloc allocates memory less than 4KB?

If malloc calls VirtualAlloc() function to allocate memory (which allocates minimum 4Kb), how malloc allocates 4 bytes for int?
user3245337
  • 147
  • 9
4
votes
2 answers

Higher than expected memory usage with VirtualAlloc; what's going on?

Important: Scroll down to the "final update" before you invest too much time here. Turns out the main lesson is to beware of the side effects of other tests in your unittest suite, and to always reproduce things in isolation before jumping to…
timday
  • 24,582
  • 12
  • 83
  • 135
4
votes
1 answer

Running a program from a byte array using VirtualAlloc?

I'm working on application SFX / Protector in C# and i want the protected assembly to be executed from a byte array instead of writing it to hard disk, in order to be much harder for reverse engineering. I have a program within a byte array ( which…
Rafik Bari
  • 4,867
  • 18
  • 73
  • 123
3
votes
1 answer

What is Linux/POSIX equivalent of VirtualAlloc with MEM_TOP_DOWN?

What is Linux or POSIX equivalent of VirtualAlloc with MEM_TOP_DOWN, if there's any?
frp
  • 1,119
  • 1
  • 10
  • 30
3
votes
7 answers

Memory allocation on Windows C code

I'd like to know which method is recommended on Windows C programming: using malloc or the Win32 HeapAlloc (maybe VirtualAlloc?) function. I've read the MSDN Memory Management Functions article and the MSDN articles regarding malloc and HeapAlloc,…
Fábio
  • 3,291
  • 5
  • 36
  • 49
2
votes
3 answers

Contiguous VirtualAlloc behaviour on Windows Mobile

I have been optimising memory performance on a Windows Mobile application and have encountered some differences in behaviour between VirtualAlloc on Win32 and Windows CE. Consider the following test: // Allocate 64k of memory BYTE *a =…
Steven
  • 3,878
  • 3
  • 21
  • 21
2
votes
1 answer

VirtualAlloc and Python - Access Violation

Very simple python script is giving me an access violation and I just can't figure out why. import ctypes def Test(): data = bytearray( "\xDE\xAD\xBE\xEF\x0B\xAD\xC0\xDE", 'utf-16' ) dataLen = len( data ) try : ptr =…
OneKneeToe
  • 85
  • 7
2
votes
3 answers

Converting a pointer to a byte slice

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…
Awn
  • 817
  • 1
  • 16
  • 33
1
2 3 4 5