C (93/257)

From:
Date:09 Feb 2001 at 00:21:50
Subject:Re: Alloc/Free___ Chip memory fragmentation

Czesc William!

Dnia 08-Lut-01, William Robinson napisa�:

>hello there once again.
>thank you for your help so far. it is amazingly appreciated.

Your's attached source code has a lot of bugs and it signals that you aren't
using real debug utilities like Enforcer or (better) MuGuardianAngel (probably
because you haven't MMU in your 030 CPU)... I sugest you to buy 040/060
accelerator ;) It'll help you programming a lot... BTW, reading memory that
you freed couple lines above isn't a good idea...

If your program which allocates and frees bitmaps would support older systems
like AmigaOS v2.0 you should create and use following functions:

VOID FreeCustomBitMap( struct BitMap *bitmap )
{
if( bitmap )
{
if( GfxBase->lib_Version >= 39 )
FreeBitMap( bitmap );
else
{
ULONG i;
for( i = 0; i < bitmap->Depth; i++ )
if( bitmap->Planes[ i ] ) FreeRaster( bitmap->Planes[ i ],
bitmap->BytesPerRow << 3, bitmap->Rows );
FreeMem( bitmap, sizeof( struct BitMap ) );
}
}
}

struct BitMap *AllocCustomBitMap( ULONG width, ULONG height, ULONG depth,
ULONG flags, struct BitMap *friendbitmap )
{

struct BitMap *bitmap;

/*
* If AmigaOS v3.0+ is available use modern bitmap allocating
* functions.
*/
if( GfxBase->lib_Version >= 39 )
bitmap = AllocBitMap( width, height, depth, flags, friendbitmap );
else
{
if( bitmap = AllocMem( sizeof( struct BitMap ), MEMF_ANY | MEMF_CLEAR )
)
{
ULONG i;
InitBitMap( bitmap, depth, width, height );
for( i = 0; i < depth; i++ )
{
if( bitmap->Planes[ i ] = AllocRaster( bitmap->BytesPerRow << 3,
bitmap->Rows ) )
BltClear( [...] );
else
break;
}
if( i != depth )
{
FreeCustomBitMap( bitmap );
bitmap = NULL;
}
}
}

return( bitmap );

}

if not (ie. it requires KS V39+) you *should* use AllocBitMap() and
FreeBitMap() only!

BTW double buffering method which you used in attached source code: it very
old method which was good in AmigaOS v1.x/v2.x... In modern programs (or
games) you really should use double/multiple buffering provided in AmigaOS
v3.0+ graphics.library functions or using multiple width/height screen and
switching visible parts using ScrollVPort() (see autodocs for more
informations) (it's probably the fastest and the best solution for you, it
works in RTG systems like CGFX or P96 as well).

Regards!



Can your ImageFX paint like bitmap painters?
Download: gfx/ifx/REDFiX.lha, ftp.novadesign.com

Przemyslaw 'SENSEI' Gruchala

code/gfx2d/gfx3d/webmaster

Amiga 1200
Apollo 1240/33 MHz, 18 MB RAM, BTC 33.6 bps
HDD 3.2 GB, HDD 520 MB, CD x12



Prezentacja oferty i sprzedaz produktow Twojej firmy w Centrum e-biznesu
teraz za niecala zlotowke dziennie!
KLIKNIJ I ZAMOW http://www.getin.pl/centrum/es_logon.asp

------------------------ Yahoo! Groups Sponsor ---------------------~-~>
eGroups is now Yahoo! Groups
Click here for more details
http://click.egroups.com/1/11231/0/_/451227/_/981679867/
---------------------------------------------------------------------_->