IonicWind Software

IWBasic => General Questions => Topic started by: REDEBOLT on September 24, 2007, 09:55:47 PM

Title: ALLOCMEM
Post by: REDEBOLT on September 24, 2007, 09:55:47 PM
I attempted to test the allocmem program from the help file, but it fails to work.
I don't understand why.

$Main
autodefine "off"
openconsole

DEF mymem as MEMORY
IF ALLOCMEM(mymem,100,10)
    PRINT "Allocated 1000 bytes of memory"
    FREEMEM mymem
else
    print "Error in allocation"
ENDIF

DO:UNTIL INKEY$ <> ""
closeconsole
END
Title: Re: ALLOCMEM
Post by: Barney on September 25, 2007, 01:23:35 AM
Read the manual. Here's the important part about MEMALLOC function:

Return value
Returns 0 on success or -1 on failure. Function may fail if the size requested is larger than the amount of free memory available.

So, what you need is either change the test like this:

IF ALLOCMEM(mymem,100,10)=0

or change the position of messages like this:


IF ALLOCMEM(mymem,100,10)
    print "Error in allocation"
else
    PRINT "Allocated 1000 bytes of memory"
    FREEMEM mymem
ENDIF


Barney
Title: Re: ALLOCMEM
Post by: REDEBOLT on September 25, 2007, 02:51:59 PM
 :-[
Thanks Barney, I should RTFM.  I took the example at face value and it is apparently wrong and should be corrected.