Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Avoid memory corruption in shared memory used by several processes?

Reply
Thread Tools

Avoid memory corruption in shared memory used by several processes?

 
 
Sune
Guest
Posts: n/a
 
      07-06-2007
Hi all,

I want to make data stored in-memory (not disk) available to several
processes. My concern is that poorly written C applications with
dangling pointers may(will) damage the data in this memory segment if
it is open to all, i.e. shared memory mapped into all processes memory
area.

I don't want to use TCP/IP client/server between the apps and a data
store process due to the overhead.

I don't want to start calculating checksums for all updates in a
shared memory area, since that means a lot of overhead.

Now my question:
Is it possible to expose just the interface of a data store component
and have that i/f shared between all processes who want to access the
data, and then have this shared interface make callbacks into a data
store process' private memory?

If yes, how do I achieve this? If not, why not?

Thanks for helping out
/Sune

 
Reply With Quote
 
 
 
 
user923005
Guest
Posts: n/a
 
      07-06-2007
On Jul 5, 7:50 pm, Sune <(E-Mail Removed)> wrote:
> Hi all,
>
> I want to make data stored in-memory (not disk) available to several
> processes. My concern is that poorly written C applications with
> dangling pointers may(will) damage the data in this memory segment if
> it is open to all, i.e. shared memory mapped into all processes memory
> area.
>
> I don't want to use TCP/IP client/server between the apps and a data
> store process due to the overhead.
>
> I don't want to start calculating checksums for all updates in a
> shared memory area, since that means a lot of overhead.
>
> Now my question:
> Is it possible to expose just the interface of a data store component
> and have that i/f shared between all processes who want to access the
> data, and then have this shared interface make callbacks into a data
> store process' private memory?
>
> If yes, how do I achieve this? If not, why not?


Try news:comp.programming.threads

 
Reply With Quote
 
 
 
 
Thad Smith
Guest
Posts: n/a
 
      07-06-2007
Sune wrote:

> I want to make data stored in-memory (not disk) available to several
> processes. My concern is that poorly written C applications with
> dangling pointers may(will) damage the data in this memory segment if
> it is open to all, i.e. shared memory mapped into all processes memory
> area.
> ...
> Is it possible to expose just the interface of a data store component
> and have that i/f shared between all processes who want to access the
> data, and then have this shared interface make callbacks into a data
> store process' private memory?


Something like that is possible, although callbacks are used for
something different than what your describe. Standard C doesn't support
multiple processes, so this is off-topic in this newsgroup.

You need to check systems that support multiple processes. It may also
be possible, in some systems, to allow a single process to write an area
of memory and others to only read.


--
Thad
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      07-06-2007
user923005 <(E-Mail Removed)> writes:
> On Jul 5, 7:50 pm, Sune <(E-Mail Removed)> wrote:
>> I want to make data stored in-memory (not disk) available to several
>> processes.

[...]
> Try news:comp.programming.threads


I suspect that's not the right place to ask. The OP asked about
processes, not threads; in many system, those are quite different
things.

It's probably better to ask in a newsgroup that deals with whatever
operating system the OP is using. At a guess, comp.unix.programmer
seems likely.

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      07-06-2007
Keith Thompson wrote:
> user923005 <(E-Mail Removed)> writes:
>> Sune <(E-Mail Removed)> wrote:
>>
>>> I want to make data stored in-memory (not disk) available to
>>> several processes.

>
> [...]
>> Try news:comp.programming.threads

>
> I suspect that's not the right place to ask. The OP asked about
> processes, not threads; in many system, those are quite different
> things.


To share memory you either need threads or some other arrangement
to specifically share a memory block. Threads are probably the
easiest initial mechanism.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
cbfalconer at maineline dot net



--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      07-06-2007
CBFalconer <(E-Mail Removed)> writes:
> Keith Thompson wrote:
>> user923005 <(E-Mail Removed)> writes:
>>> Sune <(E-Mail Removed)> wrote:
>>>
>>>> I want to make data stored in-memory (not disk) available to
>>>> several processes.

>>
>> [...]
>>> Try news:comp.programming.threads

>>
>> I suspect that's not the right place to ask. The OP asked about
>> processes, not threads; in many system, those are quite different
>> things.

>
> To share memory you either need threads or some other arrangement
> to specifically share a memory block. Threads are probably the
> easiest initial mechanism.


<OT>
How exactly do threads help you share memory between proceses?

Unix-like systems typically have mechanisms to share memory between
processes; these mechanisms are independent of threads, which exist
within a single process.
</OT>

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      07-06-2007
Keith Thompson wrote:
> CBFalconer <(E-Mail Removed)> writes:
>

.... snip ...
>
>> To share memory you either need threads or some other arrangement
>> to specifically share a memory block. Threads are probably the
>> easiest initial mechanism.

>
> <OT>
> How exactly do threads help you share memory between proceses?
>
> Unix-like systems typically have mechanisms to share memory between
> processes; these mechanisms are independent of threads, which exist
> within a single process.
> </OT>


Because, at least in my mind, threads of a process all operate in
the same memory space, and all we have to do is control access.
Processes go to some trouble to keep the memory isolated.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
cbfalconer at maineline dot net



--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      07-06-2007
CBFalconer <(E-Mail Removed)> writes:
> Keith Thompson wrote:
>> CBFalconer <(E-Mail Removed)> writes:
>>

> ... snip ...
>>
>>> To share memory you either need threads or some other arrangement
>>> to specifically share a memory block. Threads are probably the
>>> easiest initial mechanism.

>>
>> <OT>
>> How exactly do threads help you share memory between proceses?
>>
>> Unix-like systems typically have mechanisms to share memory between
>> processes; these mechanisms are independent of threads, which exist
>> within a single process.
>> </OT>

>
> Because, at least in my mind, threads of a process all operate in
> the same memory space, and all we have to do is control access.
> Processes go to some trouble to keep the memory isolated.


Yes, and the OP specifically asked about sharing memory among
*processes*. Maybe threads are a better solution to his underlying
problem, but you should at least mention that you're suggesting an
alternative rather than answering his actual question.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
user923005
Guest
Posts: n/a
 
      07-06-2007
On Jul 6, 3:37 pm, Keith Thompson <(E-Mail Removed)> wrote:
> CBFalconer <(E-Mail Removed)> writes:
> > Keith Thompson wrote:
> >> CBFalconer <(E-Mail Removed)> writes:

>
> > ... snip ...

>
> >>> To share memory you either need threads or some other arrangement
> >>> to specifically share a memory block. Threads are probably the
> >>> easiest initial mechanism.

>
> >> <OT>
> >> How exactly do threads help you share memory between proceses?

>
> >> Unix-like systems typically have mechanisms to share memory between
> >> processes; these mechanisms are independent of threads, which exist
> >> within a single process.
> >> </OT>

>
> > Because, at least in my mind, threads of a process all operate in
> > the same memory space, and all we have to do is control access.
> > Processes go to some trouble to keep the memory isolated.

>
> Yes, and the OP specifically asked about sharing memory among
> *processes*. Maybe threads are a better solution to his underlying
> problem, but you should at least mention that you're suggesting an
> alternative rather than answering his actual question.


Sharing memory between processes is actually a lot easier than sharing
memory among threads. The same ideas apply except that threads also
share the memory within the process.

I suspect that if the O.P. just wants to know how to create, use, and
destroy a shared memory segment then he will have to look at the
documentation for the operating system that he is using or use an
abstraction layer like ACE.

The guy who wrote FastDB has some C shared memory libraries that make
Windows boxes look like POSIX machines for shared memory calls. Of
course, that won't help much if the O.P. is not on Windows or POSIX
type operating systems.
His site is:
http://www.garret.ru/~knizhnik/
but I can't seem to connect right now.

 
Reply With Quote
 
Stephen Sprunk
Guest
Posts: n/a
 
      07-06-2007
"Keith Thompson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> <OT>
> How exactly do threads help you share memory between
> proceses?
>
> Unix-like systems typically have mechanisms to share memory
> between processes; these mechanisms are independent of
> threads, which exist within a single process.


Threads are sometimes referred to as lightweight processes.

> </OT>


S

--
Stephen Sprunk "Those people who think they know everything
CCIE #3723 are a great annoyance to those of us who do."
K5SSS --Isaac Asimov


--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Avoid memory corruption in shared memory used by several processes? Sune C Programming 5 07-13-2007 02:29 PM
RDOC: several related modules in several C files Victor \Zverok\ Shepelev Ruby 3 03-16-2007 04:15 PM
Avoid having a SQL express for web parts and avoid personalization Roger23 ASP .Net 2 10-12-2006 10:54 PM
Shared variable storage/ Encryption Corruption Phil C. ASP .Net Security 0 06-29-2005 04:58 PM
Avoid wasting time or how to avoid initialization Alexander Malkis C++ 8 04-13-2004 11:23 PM



Advertisments