REALBasic newbie question: structs and pointers? 
Author Message
 REALBasic newbie question: structs and pointers?

Hi,
I am an experienced PowerPlant (C++) user and have just started using
RB. I have quickly perused the developer's guide, and I have a few
questions.

Is there a RB equivalent to the C/C++ struct?. I need to read chunks
of data from a file that is formatted as structs. Also can do you do
pointer arithmetic in RB? (I know it defeats the elegance and memory
management features of RB, but I really need it for speed).

thanks



Mon, 10 Nov 2003 23:13:54 GMT  
 REALBasic newbie question: structs and pointers?

Quote:

> Is there a RB equivalent to the C/C++ struct?

No.
Make a class.
Add properties and make a method to read the properties from a
binarystream.

Mfg
Christian

--
Als wir von Mac Plus auf LC umgestellt haben, dachten die Leute, der
Rechner sei die Festplatte. Ich hatte 'nen 20-Z?ller draufstehen. Die
Leute haben immer den Rechner gesucht. Die dachten, das w?re nur der
Standfu? dazu... http://www.christians-software.de



Tue, 11 Nov 2003 01:56:11 GMT  
 REALBasic newbie question: structs and pointers?

Quote:

> Hi, I am an experienced PowerPlant (C++) user and have just started
> using RB. I have quickly perused the developer's guide, and I have a
> few questions.
> Is there a RB equivalent to the C/C++ struct?. I need to read chunks
> of data from a file that is formatted as structs. Also can do you do
> pointer arithmetic in RB? (I know it defeats the elegance and memory
> management features of RB, but I really need it for speed).

There is no struct in REALbasic. It would make dealing with the OS so
much better, but it doesn't exist.

You can use memoryblocks to handle structs. But you have to calculate
the offset yourself! You can't do MyStruct->len=6 or anything like
that.

Pointers aren't in RB. You can use a memoryblock, or use a plugin.
MemoryBlocks are quite fast, a plugin that gives pointers is around 3x
faster. Hmmmm, and plugins have quite a bit of overhead so it just goes
to show what we are missing out on with pointers.

Seeing as you are experienced in C, you can use RB in it's best way.
Use RB as something complimentary to C, and not to replace it! That is,
you can write code in C, and use it in RB via plugins. That way you get
all the benefits of C, and RB at the some time.

--
Email Cleaner does convenient re-wrapping on badly wrapped emails and
newsgroup-posts. Badly wrapped lines is a problem every Internet User
comes across, Email Cleaner solves it! It also has many other features.

Email Cleaner works from inside all of your Mac programs, from one
button click.

<www.elfdata.com/emailcleaner/>



Tue, 11 Nov 2003 16:36:58 GMT  
 REALBasic newbie question: structs and pointers?


Quote:
> Is there a RB equivalent to the C/C++ struct?. I need to read chunks

An RB class is the equivelant to a struct. Remember, the only difference
between a C++ struct and a C++ class is that a struct defaults to public
members and a class defaults to private. By default, RB properties and
methods are public (you have to state them as private). So an RB class is
the same as a C++ struct =).

Quote:
> of data from a file that is formatted as structs. Also can do you do
> pointer arithmetic in RB? (I know it defeats the elegance and memory
> management features of RB, but I really need it for speed).

The closest you'll get to this in RB is to use the MemoryBlock object (which
is actually very nice). Just load it up with bytes and read them however you
want.

Jeff



Tue, 11 Nov 2003 21:22:54 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Newbie Question: Realbasic Question

2. Python OOP newbie question: C-Struct-esque constructions

3. newbie question: structs in python

4. newbie question - what is realbasic - from a windows programmer

5. Newbie RealBasic Questions

6. RealBasic Newbie Questions

7. newbie REALbasic question (random numbers)

8. New newbie question: tagged pointers

9. NEWBIE - pointer question

10. Newbie question about pointers in GNAT 3.15p on Windows 2000

11. Newbie question ... regarding pointers

12. POINTER question (newbie)

 

 
Powered by phpBB® Forum Software