Is there an equivalent of VirtualAlloc on Android NDK? - android-ndk

I'm looking into virtual memory management with android ndk and was wondering if there is an equivalent to the VirtualAlloc/Free family of functions in the android ndk, and if so, where can I find some docs on them.
Thank you for your time.

On Android, all memory allocations are "virtual", in the sense that the memory is not committed unless it is really accessed. If I remember correctly, VirtualAlloc comes from Windows CE, where the memory per process was artificially limited to 32 MByte (see http://denniskrabbe.wordpress.com/2009/10/09/windows-mobile-heaps-from-the-large-memory-area/). On Android, the limitations are the natural ones of a 32-bit architecture (iOS has recently entered the 64-bit era). There are some limitations on the JVM heap size, but they do not apply to native (NDK) memory (see Maximum native memory that can be allocated to an android app)
In Android, just like any Linux, malloc is optimistic, which means you can encounter out-of-memory after your malloc succeeded, see Does malloc lazily create the backing pages for an allocation on Linux (and other platforms)?. On the other hand, bionic does not provide custom memory allocation hooks as glibc.

Related

Debugging Memory Leak

I'm trying to figure out where my memory leak is coming from since lately i'm experiencing a lot of performance drop when just opening a new tab on my browser FireFox ver.51
Just to be sure I've disabled all non-Microsoft startup services in msconfig even after reboot it still gets stuck on this.
Looking up on the vendors updates for this machine then it would be up to date on the drivers, i do occasionally check for Intel Chipset and onboard Graphics drivers (stable versions only) myself that are a few years newer then the vendor.
MS Resource monitor
MS Taskmgr Perfomance monitor
In the Taskmgr Performance monitor you can see I'm barely using any CPU and I/O leaving out any form of I/O wait issues due to swapping.
When looking in the Resource monitor actual physical RAM in is about 6.3GB while Cached is only 1.6GB making it roughly 4GB RAM missing where it's usage is coming from.
So i did do a offline MemTest (oh yes the old blue gorgeous BIOS screen) and all checks were passed, luckily it's only 8GB RAM so the downtime is manage-able ;)
Any ideas or other handy tools I can use to find the culprit?
Already fixed it, seems like my pagefile is storing too much cached memory for some reason, will look into it myself why it stores so much memory

Windows Program Memory Vs Linux Program Memory

Linux creates virtual memory pages for every program to use, and the OS handles mapping the virtual addresses to genuine hardware addresses, correct?
But how does Windows do this? Do Windows programs actually have memory that translates to real hardware addresses? I'm also aware that windows can use hard disk memory when RAM is over used, and this process is again called virtual memory, but I believe this is an entirely different concept?
Windows and Linux (at least on Intel 32/64 bit systems) both implement virtual memory using the same mechanism: hardware supported page tables. The OS and the hardware cooperate together to do the address mapping.
The entire concept of separating the logical addresses a program uses from the physical addresses is what is called virtual memory. The use of the hard disk as a backing store is an implementation of virtual memory that uses a swap file to increase the amount of virtual memory to an amount greater than the physical memory installed in the system.
Virtual memory is a pretty deep and wide subject. Maybe start with this Wiki article an Memory Management and then hit the googles for a deeper understanding.

Memory mapped I/O on the riscv rocket core

How can I do uncached memory accesses on the rocket? Is there a way to specify which regions of the memory map that should have caches enabled or disabled?
I can not find anything about this in any documentation, but if I have overlooked something I would be happy to receive a link to where this is documented.
Asbjørn
This was answered on the riscv sw-dev mailing list. It is not possible to do uncached memory access on the rocket core.
https://lists.riscv.org/lists/arc/sw-dev/2014-10/msg00025.html :
Rocket's data cache doesn't support uncached loads and stores. Our test chips perform I/O using control registers via the CSRxx instructions.

j2me wtk find memory leak

I built a game in j2me and I have memory leak because from time to time I get out of memory exception, now I want to spot where this leak is coming from and I heard you can do it with sun's wireless tool kit. Can someone explain me exactly what is this wireless tool kit, how I install it and how to use it in-order to find memory leaks ? Thanks in advance !
After you download wtk,Go to \bin\utilsw.exe.Under Utilities you will see "Memory monitor".Here you can graphically view app memory/RAM usage.
I do not know oracle sdk 3.4, but in wtk2 memory monitor was only partially useful for finding memory leaks, because it only shows how many (and which) objects are live, but not where they are referenced from. So it takes a review of corresponding piece of code.
Memory leaks are easier to find with a java profiler. You need to get one that suits you (I prefer YourKit, but it is commercial product with a trial period), modify emulator's command line in order to allow the profiler to connect (that should be covered by profiler's documentation, it is basically about adding -agentlib or -Xrun... option) to it, and do actual profiling (every profiler comes with a guide of how to do it).

how to get correct physical memory and virtual memory

I use this windows API,
http://msdn.microsoft.com/en-us/library/aa366589(v=vs.85).aspx
GlobalMemoryStatusEx to get memory information
my computer total physcial memory is 4096MB ,why the program shows 3.XG
My computer's virtual memory is 3063MB ,but i use program which show 2047MB
my develop enviroment is visual studio 2008
how to modify this problem
thanks
Aren't other programs using your system as well? I suspect the memory you're "missing" is due to the OS itself and whatever other programs you're running. See if having a bunch of other applications open changes the virtual memory size that your program is able to see.
Assuming you are running a 32bit version of windows, then this is a limit of windows itself. See this Microsoft page for the details. By default you will only be able to access 2GB of RAM in a single process. There is a compiler switch in visual studio which will give you access to 3GB. This is the /LARGEADDRESSAWARE switch. Beyond that you just need to upgrade to a 64bit operating system.
By the way, the basic reason why you don't automatically get 4GB of address space is because part of it is reserved for the operating system. Those system calls and references to operating system resources have to live somewhere.

Resources