Welcome, Guest. Please login or register.

Author Topic: "Close Window" tutorial errors  (Read 3941 times)

Description:

0 Members and 1 Guest are viewing this topic.

Online Thomas

Re: "Close Window" tutorial errors
« on: May 10, 2003, 06:14:24 PM »
Quote

>45 struct IntuiText *MyText;

this fills me with dread, surely that should be:

>45 struct IntuiText *MyText = new IntuiText;

but does that mean i have to "free" it when i shutdown?


Of course you must allocate some memory if you use a pointer. But "new" is not the right thing here. I guess the tutorial is about C, not C++. Use AllocMem/FreeMem instead. Or use struct IntuiText MyText instead of *MyText.

Quote

>54 PrintIText( MyWindow->RPort, MyText, 0, 0 );

changing it to this:

>54 PrintIText( MyWindow->RPort, MyText, MyWindow->BorderLeft, MyWindow->BorderTop );

offsets it into the window's window bit. i learnt that by reading intuition.h


Just add the GimmeZeroZero flag, then Intuition does that for you.


Quote

>104 CloseLibrary( (struct Library *)IntuitionBase );

This caused shell lockups and all sorts of memory trouble, it worked cleanly when i made it:

>104 CloseLibrary( IntuitionBase );


But the former is correct. You should include , and to give the compiler the chance to inform you about wrong types.

Quote

cycloid - willing and able C++ coder who's struggling through lack of documentation!


Get the Amiga Developer CD. There is a lot of documentation on it and it is the *official* documentation. You really need it. Trial and error is not the right way to learn programming, because only documented features continue to work in future OS versions.

Bye,
Thomas

Online Thomas

Re: "Close Window" tutorial errors
« Reply #1 on: May 11, 2003, 09:29:08 AM »
Quote

You're exactly right, AllocVec() and FreeVec() are very much akin to ANSI C's malloc() and free(). The only difference is that AllocVec() allows you to specify different Amiga specific types of memory such as Chip RAM, Fast RAM, etc.


There is one additional major difference, mostly important for lazy (bad) programmers: malloc() does resource tracking. You can return from the program without explicitely calling free() and the startup code will return all allocated memory. Each AllocVec() *must* be matched by a FreeVec().

Bye,
Thomas