Odd Buffer problem

The forum for all of your Freebasic needs!

Moderators: Pete, Mods

Post Reply
User avatar
Mentat
Veteran
Posts: 409
Joined: Tue Aug 07, 2007 3:39 pm
Location: NC, US

Odd Buffer problem

Post 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.
For any grievances posted above, I blame whoever is in charge . . .
User avatar
Kiyotewolf
Veteran
Posts: 96
Joined: Tue Apr 01, 2008 11:38 pm

huh?

Post by Kiyotewolf »

you lost me at constructor..

isn't that a transformer toy?

constructor.. FB keyword??
Banana phone! We need more lemon pledge. * exploding fist of iced tea! * I see your psycho cat and counter with a duck that has a broken leg, in a cast.
coderJeff
Coder
Posts: 16
Joined: Tue Jan 08, 2008 8:14 am

Post 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
User avatar
Mentat
Veteran
Posts: 409
Joined: Tue Aug 07, 2007 3:39 pm
Location: NC, US

Post 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. :)
For any grievances posted above, I blame whoever is in charge . . .
User avatar
Kiyotewolf
Veteran
Posts: 96
Joined: Tue Apr 01, 2008 11:38 pm

wow.. odd

Post 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.
Banana phone! We need more lemon pledge. * exploding fist of iced tea! * I see your psycho cat and counter with a duck that has a broken leg, in a cast.
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Who are you talking to KYOTE?

Post by burger2227 »

I think nobody is listening anyhow LOL
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
User avatar
Mentat
Veteran
Posts: 409
Joined: Tue Aug 07, 2007 3:39 pm
Location: NC, US

Re: wow.. odd

Post 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.
For any grievances posted above, I blame whoever is in charge . . .
User avatar
Mentat
Veteran
Posts: 409
Joined: Tue Aug 07, 2007 3:39 pm
Location: NC, US

?

Post by Mentat »

Once again for the umpteenth time, I have the feeling I'm missing something . :|
For any grievances posted above, I blame whoever is in charge . . .
Post Reply