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 / 2175
2174  |  2176
Subject: 
How to make shared memory....not
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Sat, 22 Dec 2001 11:10:12 GMT
Viewed: 
1703 times
  
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.

-------------- 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
 
(...) 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 & (...) (23 years ago, 27-Dec-01, to lugnet.robotics.rcx.legos)

Message is in Reply To:
  Re: Storing Data
 
(...) It was suggested by some of my 'c++' co-workers that this was the case (shared memory was available). However, I don't deal with that in my Visual Basic world. They also suggested there were 'unused' memory blocks in LegOS where data could be (...) (23 years ago, 21-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