object oriented programming: pointer passing
Chris Micro
Posts: 160
Hello Together,
how can I pass one Object as an argument to another object?
Here is the problem:
Lets assume someone wants to write a windows manager. To initialize the windows manager it is necessary to pass the pointer of the vga driver so the vga functions can be used.
Has anyone an idea how to do it in spin?
Thanks,
chris
how can I pass one Object as an argument to another object?
Here is the problem:
Lets assume someone wants to write a windows manager. To initialize the windows manager it is necessary to pass the pointer of the vga driver so the vga functions can be used.
Has anyone an idea how to do it in spin?
Thanks,
chris
Comments
You could have 3 or 4 objects... your top object would talk to your i/o manager, your window manager and the vga driver.
If you are trying to figure things out after reading the manual... don't. The manual is intended mostly as a reference guide. If you are really experienced, you can get buy with just the manual.
Take a look at the education labs. If you go through them in sequence, everything will be a lot easier.
Rich
SPIN is not an object oriented language in the sense you are probably used to. It uses some object-oriented terminology (e.g. calling functions 'methods), but what SPIN calls 'objects' are primarily a packaging convenience. They are more like what other languages call 'units' (e.g. Ada) or 'modules' (e.g. Modula-2).
Ross.
-Phil
If you are using VGA_Text.spin and VGA.spin for example, all the per instance VAR
variables in VGA_Text.spin need to be converted to global DAT variables. This will
let you call vga.str(...) from any object that includes OBJ vga : "VGA_Text".
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--Steve
Propalyzer: Propeller PC Logic Analyzer
http://forums.parallax.com/showthread.php?p=788230
Isn't this the main cause for the OBEX?
The idea was to be able to write a main programm with
obj vga_text
obj windows
...
They are glued together in the main program. But to use windows, it is necessary to pass the object.
That sounds very awkward to handle. What if someone wants to exchange the vga_text by tv_text? The procedure has to be done again.
Is there a good way how this problem can be solved?
http://forums.parallax.com/showthread.php?p=765086
Everything you want to do... you actually can do with the Prop.
One of the problems I had was in my own preconceptions about how I thought things
would work. It is amazing how confusing it can be, if you start out with the wrong constructs.
You can have two objects calling the same driver, you just have to include the driver in two places and initialize it. Two different uses can have two different sets of initialization data, and Spin is clever enough to keep things separate in a very compact and efficient manner.
You will hear that there are no pointers in Spin... there are pointers all over the place, but each one has a specific purpose and is intended to be used in a specific way, and they aren't called pointers[noparse]:)[/noparse]
If you want to do something really complicated... you are going to have to be able to access lots of information. Right now, the best memory objects are for SD cards. There is a way to directly invoke a spin program and use data stored to a work file directly from an SD card... So, the sky is the limit. I'm not a professional programmer... but I think there is a general concept called "context switching." In the case of the Prop,
the easiest way to switch contexts is to load a Spin program for each context switch and then populate your variables from a file you keep on your SD card. I've experimented with the general idea... it works and it is fast enough to be transparent to the user.
Take a look at Oldbit's PropDos... lots of good stuff and your window manager would fit right in[noparse]:)[/noparse]
Rich
I've been down the road you are on. Your question is the first one I asked when I joined the forum last year ... the only reason I joined. I've been angry because the product did not fit my ideal. In the end one throws up one's hands and lives with the limitations or moves on to a better fit. The lack of memory is the biggest challenge though it has been fun trying to overcome that.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--Steve
Propalyzer: Propeller PC Logic Analyzer
http://forums.parallax.com/showthread.php?p=788230
http://forums.parallax.com/showthread.php?p=777920
Meanwhile I wrote a mini minimalistic window manager ( don't expect to much ) to test the concepts I can use in Spin.
I tried to have a very clear structure of the window object.
I would be glad if someone likes to discuss the structure and if it is suitable.
There are heaps of problems which I discovered:
1. somehow it is difficult to use strings and pointers with the bytemove command
2. is there a dynamic memory allocation mechanism?
Because the windows can have different sizes and in the example program I have to reserve always memory for the maximum size
2) There's no built-in dynamic memory allocation mechanism. With the limited memory available, a generalized dynamic memory allocator is not that useful although one was written and is in the Object Exchange. I wrote a Propeller OS a long time ago that's referenced in one of the permanent thread indices (http://forums.parallax.com/showthread.php?p=609066). This was designed to use either a TV or a VGA display driver and allocated work areas for the various I/O drivers dynamically from the high end of memory downwards towards the stack.
If you want to write a preprocessor (that will run on a mac) than I'll finish off DOL.
I tried writing a window manager as well using the graphics driver. Wasn't very useful though because I didn't have enough memory. If you keep everything text based though it shouldn't be a problem. One comment on the code you attached is that just returning a string isn't going to be very helpful if you want your windows arbitrary sizes and places. You'll need to also include the width, height and position to the drawing routine. There has been at least one other window manager. Can't remember where I got it from so I've attached it.
Hi Mike, this is a very usefull link list I didn't know. It takes somehow time until I can find all information for the propeller
>1) It's not difficult to use strings and pointers with the BYTEMOVE statement. What problems are you having?
The problem in my first example was that for the title there were only 4 chars written on the screen. I discoverd now that the strlength method didn't work:
I replace it by this, which works
Congratulations to your work
My litle example is not meant to be a Operating system. I just want to see how far some object oriented principles are usefull on the propeller.
And probably even the example programm might be usefull: it should be a simplicistic window manager. With the limited screen size it is often very helpfull to divide the screen in several tiles ( windows ) and to direct the ouput to this windows.
I tried to implement some obect oriented principles I know from java: the getters and setters
In my example I create several window objects. But I need some internal buffers in the object.
For windows with smaller size less buffer memory would be needed. But I don't know how to create windows with different buffersize.
As attachement the improved window version.
chris