On Mon, 23 Nov 2009, Maurilio Longo wrote:
Hi,
> yes, DosAllocMem() and DosQueryMem() should be enough. I'm not sure about the
> coalescing thing, since DosQueryMem() gives you back size of a memory object
> in bytes and access control flags while the windows version seems to be giving
> back more infos.
It should not be a problem. VirtualQuery() is used to free continues memory
region allocated in more then one VirtualAlloc() calls and seems that we can
easy replicate all MS-Windows conditions using DosQueryMem()
Seems that the final version can look like the code below.
I'm only not sure about OBJ_TILE usage. In fact it's optional to reduce
fragmentation so we do not have to use it at all but if we can find sth
to for allocation virtual memory addresses from two different sides of
process virtual address space then it will be nice.
#define INCL_DOSMEMMGR
/* OS/2 MMAP via DosAllocMem */
static void* os2mmap(size_t size) {
void* ptr;
if (DosAllocMem(&ptr, size, PAG_COMMIT|PAG_READ|PAG_WRITE) != 0 )
return MFAIL;
return ptr;
}
/* For direct MMAP, use OBJ_TILE to minimize interference */
static void* os2direct_mmap(size_t size) {
void* ptr;
if (DosAllocMem(&ptr, size, PAG_COMMIT|PAG_READ|PAG_WRITE|OBJ_TILE) != 0 )
return MFAIL;
return ptr;
}
/* This function supports releasing coalesed segments */
static int os2munmap(void* ptr, size_t size) {
while (size) {
ULONG ulSize = size, ulFlags = 0;
if (DosQueryMem(ptr, &ulSize, &ulFlags) != 0)
return -1;
if ((ulFlags & PAG_BASE) == 0 ||(ulFlags & PAG_COMMIT) == 0 ||
ulSize > size)
return -1;
if (DosFreeMem(ptr) != 0)
return -1;
ptr = ( void * ) ( ( char * ) ptr + ulSize );
size -= ulSize;
}
return 0;
}
#define CALL_MMAP(s) os2mmap(s)
#define CALL_MUNMAP(a, s) os2munmap((a), (s))
#define DIRECT_MMAP(s) os2direct_mmap(s)
If you can confirm that it should work then I'll commit it to SVN and
I would like to ask you or David to make tests in real OS2 environment.
best regards,
Przemek
_______________________________________________
Harbour mailing list (attachment size limit: 40KB)
[email protected]
http://lists.harbour-project.org/mailman/listinfo/harbour