[LCP] mapping memory

Kim Hawtin kim.hawtin at adelaide.edu.au
Tue Nov 4 13:03:57 EST 2008


Hi Mark,

Mark Farnell wrote:
> I mean different logical address.
> 
> In a process, suppose I malloc a piece a memory
> 
> #define SIZE 1024
> 
> void *a = malloc(SIZE);
> 
> Are there any functions which produces a logical mapping of the chunk
> I've malloced on a *different* address space (but in fact point to the
> same chunk)
> 
> void *b = map(a, size);
> 
> so that b is the base address of a different block (address looks
> different to a), yet if a thread changes the content pointed to b, it
> actually maps to the block pointed to by a.
> 
> The application is that I have a process which spawns multiple POSIX
> threads.  The process malloc's a piece of memory.  Then what I intend
> to do is that for each thread, map that piece of memory to a different
> address space, each mapping can have individual mprotect operations
> that does not affect other mappings owned by other threads.
> 
> However if a mapping is written to, it actually writes to the piece of
> memory malloc'ed by the master.
> 
> So memcpy etc will *not* do the job.  I am not asking how to copy contents.
> 
> Can this be done?

inter-process stuff may be better covered by POSIX shared memory.
eg; http://linux.about.com/library/cmd/blcmdl3_shm_open.htm

alternatively, mmap might be useful, depends on your application;
eg; http://linux.about.com/library/cmd/blcmdl2_mmap.htm

otherwise start here =0
http://www.google.com.au/search?hl=en&q=posix+shared+memory+linux

regards,

Kim
-- 
Operating Systems, Services and Operations
Information Technology Services, The University of Adelaide
kim.hawtin at adelaide.edu.au



More information about the linuxCprogramming mailing list