cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
user name:
password:
Forgot your password?
please wait
try again
cancel
forgot your password?
sign up
log in
[Legacy version]
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
How do I use VirtualAlloc on the Linux p
How do I use VirtualAlloc on the Linux platform?
Sep 26, 2020 at 6:37am
Sep 26, 2020 at 6:37am UTC
ebz
(20)
Hello! I somewhat learned how to use VirtualAlloc on Windows, but not sure how to do the same thing on Linux.
I've got the following:
memory = (
unsigned
char
*)VirtualAlloc(0, memorySize, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
I'd love to allocate a chunk of memory on linux as well :(
Sep 26, 2020 at 7:04am
Sep 26, 2020 at 7:04am UTC
Thomas1965
(4571)
VirtualAlloc is Windows only.
If you use C then malloc, realloc and free are the normal choices.
If you use C++ you can use new and delete or even better use the STL containers and smart pointers.
Sep 26, 2020 at 7:07am
Sep 26, 2020 at 7:07am UTC
ebz
(20)
Hey Thomas thanks for the quick reply. I'm actually doing a personal learning project and wanted to use an equivalent and avoiding smart pointers.
Is mmap a right choice in that case? I'm not sure how to use it,
Sep 26, 2020 at 7:51am
Sep 26, 2020 at 7:51am UTC
salem c
(3712)
> Is mmap a right choice in that case?
Yes, this is the Linux equivalent function.
> I'm not sure how to use it,
Read the manual, scroll down to the example.
https://www.man7.org/linux/man-pages/man2/mmap.2.html
Sep 26, 2020 at 7:52am
Sep 26, 2020 at 7:52am UTC
ebz
(20)
Thanks :)
Topic archived. No new replies allowed.