Jump to content

simple shared memory program on C

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
kattythebest

kattythebest

    Newbie

  • Members
  • Pip
  • 4 posts
Hi folks :blink:

I want to try some shared memory program on my PC (ubuntu) .... I m scared that some mistakes (related to shared memory/sephomore) may spoil my PC' memory...Suggest some tips :rules: and simple program that can be execute on my PC:thumbup:

#2
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts
Don't worry, using shared memory won't physically harm your memory cards. :)

Shared memory in Ubuntu is actually very painless to implement. There's a folder in Ubuntu called "/dev/shm" which, as I read it, is a RAMdisk, or a shared RAM drive, that acts just like a normal folder to write data to, but is actually stored into RAM so you can output data to and get data from it just as fast as you could from normal RAM, while sharing the resource as if it were a normal file on the hard disk. Go ahead and look into it, it might be just what you're looking for...
Wow I changed my sig!

#3
kattythebest

kattythebest

    Newbie

  • Members
  • Pip
  • 4 posts
Thank you ...

#4
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,716 posts
That's publicly shared memory though, isn't it? There's a way to share memory between programs that you've written. I can't remember the exact procedure right now (it's simple, like five lines), but it's really quite useful. And more secure.

You'll have to call these functions, in this order:
shm_open (create memory object)
ftruncate (set size of memory object)
mmap (map memory object into address space)
(memory is ready to use)
munmap
shm_unlink
sudo rm -rf /