PDA

View Full Version : سوال: سوال درمورد تابع VirtualAllocEx



fahimeh1512
چهارشنبه 27 شهریور 1392, 16:06 عصر
با سلام خدمت دوستان عزیز
میخوام بدونم تابع VirtualAllocEx که تو یه فرایند مقصد فضا تخصیص میده باتوجه به نام تابع این حافظه تخصیص داده شده مجازیه یا فیزیکی؟
آخه مگه میشه یه حافظه مجازی تخصیص بدیم و توش داده بریزیم و...؟ این داده ها تو هوا که ذخیره نمیشن:متفکر:
اگه روشنم کنین ممنون میشم

rezaricky
پنج شنبه 28 شهریور 1392, 15:40 عصر
VirtualAlloc and VirtualAllocEx in very simplistic terms allocate raw pages, all other memory functions from malloc to GlobalAlloc all use VirtualAllocEx underneath. The problem with VirtualAlloc is that it is basically raw memory, there is no reallocation or relocation available. As such if your address space becomes fragmented you have no recourse but to release and rebuild.

The primary use case for VirtualAlloc is when you need to write your own memory manager, for say a SQL implementation where it can make a huge difference. Or if you were implementing a Just In Time Compiler (JIT), as you would need to be able to change the protection flags on the page you compile into from read/write to read/execute as to not trigger Data Execution Prevention.
http://stackoverflow.com/questions/17513363/for-what-do-i-need-to-use-virtualalloc-virtualallocex

این تابع در داخل Ram حافظه اختصاص میده و معمولا وقتی ازش استفاده میشه که بخوایم memory manager پیاده سازی کنیم.
توابع malloc و GlobalAlloc و ... هم در پیاده سازیشون از این تابع برای گرفتن حافظه استفاده میکنن.