Page 1 of 1

Odd Buffer problem

Posted: Tue Apr 15, 2008 2:55 pm
by Mentat
I've been having a weird Allocation problem.

If I store 640 in a short var wdth, and 480 to a short var height (screen dimensions), and then ask to allocate, the bugger fails.
If I ask to allocate a 640*480 buffer, it continues.

However, the first case works if the dimensions are smaller (but I'm not going to work with a 100*100 screen, people).

Here's some abridged code

Code: Select all

DIM AS main something = main (640,480)

'blah blah blah

CONSTRUCTOR main (wdth_ AS SHORT, height_ AS SHORT)
     wdth = wdth_     'both are SHORT
     height = height_
     SCREENRES wdth, height     

     'buffer
     buffer = ALLOCATE (wdth * height * SIZEOF (INTEGER))
END CONSTRUCTOR
This one didn't work. The buffer was null and empty.

This one did work:

Code: Select all

DIM AS main something = main

'blah blah blah

CONSTRUCTOR main
     SCREENRES 640, 480     

     'buffer
     buffer = ALLOCATE (640 * 480 * SIZEOF (INTEGER))
END CONSTRUCTOR
The resulting buffer was in good working order. The latter is nice if I am going to use 640*480, but that won't always be the case. The former is good for stamps.

huh?

Posted: Wed Apr 16, 2008 1:16 am
by Kiyotewolf
you lost me at constructor..

isn't that a transformer toy?

constructor.. FB keyword??

Posted: Wed Apr 16, 2008 8:53 am
by coderJeff
fbc doesn't do overflow checks (even with error checking enabled). The size of the result is same as whatever the largest numeric type is in the (sub)expression.

Code: Select all

dim as short x, y

x = 640
y = 480

print x * y * sizeof( integer )
print cint(x) * y * sizeof( integer )

'' OUTPUT:
'' -81920
''  1228800

Posted: Wed Apr 16, 2008 5:02 pm
by Mentat
Kiyotewolf wrote:you lost me at constructor..

isn't that a transformer toy?

constructor.. FB keyword??
A constructor is a special kind of procedure. And it's a keyword.
Such as

Code: Select all

TYPE dog
     'some data
     age AS INTEGER
     weight AS INTEGER
     
     'sets up weight, and sets age to 5
     DECLARE CONSTRUCTOR(AS INTEGER)
END TYPE

DIM AS dog fluffy=dog(12)
DIM AS dog kit=dog(15)

PRINT "Fluffy's age is ";fluffy.age
PRINT "Fluffy's weight is ";fluffy.weight
PRINT
PRINT "Kit's age is ";kit.age
PRINT "Kit's weight is ";kit.weight

SLEEP
END

CONSTRUCTOR dog (someWeight AS INTEGER)
     weight = someWeight
     age=5
END CONSTRUCTOR
And the output would be

Code: Select all

Fluffy's age is  5
Fluffy's weight is  12

Kit's age is  5
Kit's weight is  15
Thanks coderJeff. :)

wow.. odd

Posted: Wed Apr 16, 2008 10:23 pm
by Kiyotewolf
That is weird..

Kinda like a mix of a FNExpression and.. something..

Constructicons.. unite!

hahaha..

^~^

Thanks very much for the detailed info on how to use it. I may consider using it now that I know what it is.

Who are you talking to KYOTE?

Posted: Wed Apr 16, 2008 10:30 pm
by burger2227
I think nobody is listening anyhow LOL

Re: wow.. odd

Posted: Thu Apr 17, 2008 7:26 am
by Mentat
Kiyotewolf wrote:That is weird..

Kinda like a mix of a FNExpression and.. something..

Constructicons.. unite!

hahaha..

^~^

Thanks very much for the detailed info on how to use it. I may consider using it now that I know what it is.
It's pretty much a method that runs at the start of being DIMed.
And a deconstructor is the opposite.

?

Posted: Sun Apr 20, 2008 5:17 pm
by Mentat
Once again for the umpteenth time, I have the feeling I'm missing something . :|