To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.legosOpen lugnet.robotics.rcx.legos in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / legOS / 2176
2175  |  2177
Subject: 
Re: How to make shared memory....not
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Thu, 27 Dec 2001 13:35:15 GMT
Viewed: 
1883 times
  
In lugnet.robotics.rcx.legos, Michael Obenland writes:
SO...  how do I do that?  (I need commands here!)

You ask for it, you get it. BUT: It works, sort of. It will not survive any
multitasking problems. Shared memory has to be handled by the OS, not by a
user program.

I split your problem to 3 programs. Program 1 allocates the memory and prints
it address. Program 2 writes to this memory, program 3 reads from it. When
you start program 3 after running program 1 again, you will get all zeros.
But you have to hardwire the address of the memory to program 2 and three.

Thanks, Michael.  This appears to be exactly what I'm looking for.  I assume
if I want to store more values, I can just change the 'shared' struct,
right? (add l, m, n...)

When you say 'multitasking problems', you're talking about storing & reading
from different threads, right?  That won't be a problem.  I plan on doing
almost exactly what you have here.  Write in one program, and read from
other(s)



-------------- snip -------- program 1 ---------------------------

#include <conio.h>

typedef struct {
  int i, j, k;
} shared;

shared sh;

main()
{
  cputw( &sh );
  sh.i = sh.j = sh.k = 0;
  return 0;
}

----------- snip -------- program 2 -------------------------------

#include <conio.h>

typedef struct {
  int i, j, k;
} shared;

shared *psh;

main()
{
  psh = (shared *)0xb0a2;  /* enter YOUR result of prg1 here!! */
  psh->i = 123;
  psh->j = 234;
  psh->k = 345;
  lcd_int( psh->i ); sleep( 1 );
  lcd_int( psh->j ); sleep( 1 );
  lcd_int( psh->k );
  return 0;
}

------------- snip --------- program 3 --------------------------------

#include <conio.h>

typedef struct {
  int i, j, k;
} shared;

shared *psh;

main()
{
  psh = (shared *)0xb0a2; /* enter YOUR result from prg1 here!! */
  lcd_int( psh->i ); sleep( 1 );
  lcd_int( psh->j ); sleep( 1 );
  lcd_int( psh->k );
  return 0;
}

----------- snip ------- end of programs ----------------------------

Hope it hels,

Mike



Message has 1 Reply:
  Re: How to make shared memory....not
 
(...) Yes. That is the only thing you have to do. You can store whatever you want. (...) Exactly. If you know you what you do, nothing bad can happen. BTW., this scheme can be extended to something like a shared library. If you store pointers to (...) (23 years ago, 27-Dec-01, to lugnet.robotics.rcx.legos)

Message is in Reply To:
  How to make shared memory....not
 
(...) You ask for it, you get it. BUT: It works, sort of. It will not survive any multitasking problems. Shared memory has to be handled by the OS, not by a user program. I split your problem to 3 programs. Program 1 allocates the memory and prints (...) (23 years ago, 22-Dec-01, to lugnet.robotics.rcx.legos)

11 Messages in This Thread:


Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR