Memory allocation
Posted: Thu Jul 19, 2012 11:13 am
Hi,
I am a bit confused regarding the different memory types. Looking at the developer wiki this can be read:
When my subprocess uses the shared data, must it be locked in some way?
I am guessing the reason for AVT_Lock defaulting to TRUE for MEMF_SHARED is that each process possibly tinkering with the memory must know where the memory is at. In the case of MEMF_PRIVATE, the OS knows exactly which process uses the unlocked memory and can change its pointers accordinlgy to how the memory is moved.
I'm asking this partly in the context of my Java project, where the JVM handles memory allocation. I haven't yet focused on optimizing the memory handling for AmigaOS, so now I just allocate a big chunk of MEMF_SHARED memory for the Java heap. And here I would wan't to take advantage of all the new AmigaOS 4 memory stuff.
I am a bit confused regarding the different memory types. Looking at the developer wiki this can be read:
In the "Swap issue also on Update 4 ?" thread it is said:
- MEMF_PRIVATE: This memory is private and only accessible within the context of the Task which allocated it. Private memory should always be preferred. Private memory is also swappable by default (i.e. not locked). This memory will not be visible to any other address space.
- MEMF_SHARED The memory is shared and accessible by any Task in the system without restriction. This memory can be shared between all address spaces and will always appear at the same address in any address space. Shared memory is locked by default and must be explicitly unlocked with UnlockMem() prior to freeing.
- MEMF_EXECUTABLE The memory is used to store executable PowerPC code. This is used two-fold in AmigaOS. First, it allows the system to determine if a function pointer points to real native PowerPC code as opposed to 68k code which needs to be emulated. Second, it prevents common exploits that use stack overflows to execute malicious code. Executable memory is locked by default and must be explicitly unlocked with UnlockMem() prior to freeing.
How I am supposed to allocate memory I want to share between my own private Processes (or Tasks), created using CreateNewProc? Imagine I send a message to a private process with data to process, does this memory need to be MEMF_SHARED? If I want this to be swappable, and consequently not locked, could I simply set AVT_Lock to FALSE, and override the default for MEMF_SHARED?Apps should avoid using shared memory because it is locked and eats up available address space.
When my subprocess uses the shared data, must it be locked in some way?
I am guessing the reason for AVT_Lock defaulting to TRUE for MEMF_SHARED is that each process possibly tinkering with the memory must know where the memory is at. In the case of MEMF_PRIVATE, the OS knows exactly which process uses the unlocked memory and can change its pointers accordinlgy to how the memory is moved.
I'm asking this partly in the context of my Java project, where the JVM handles memory allocation. I haven't yet focused on optimizing the memory handling for AmigaOS, so now I just allocate a big chunk of MEMF_SHARED memory for the Java heap. And here I would wan't to take advantage of all the new AmigaOS 4 memory stuff.