Memory

Please use this Board for QBasic related requests ( file research, programming, etc.)

Moderators:Administrator, Global Moderator

Post Reply
Guest
Memory

Post by Guest » Sun Nov 24, 2002 8:40 pm

Yet another question for you experts... If I need an array of switches , simple values... is it more efficient memory-wise to make them string *1 or integer? In my programming experience, numbers are always far more efficient than strings, however, a QB integer is two-bytes while a string * 1 is one byte??? Is that right? If so, wouldn't it be more efficient to store these values as string * 1? Thanks for any help!

User avatar
frankiebaby
Global Moderator
Posts:95
Joined:Tue Apr 30, 2002 1:38 am
Location:Pennsylvania
Contact:

Re: Memory

Post by frankiebaby » Mon Nov 25, 2002 2:17 am

Yes, that is correct, variable length strings require 4 bytes for the descriptor, and one byte afterwords, fixed only use 1 byte each character.

You can find all the data type memory requirements in Qb's Online Help under CONTENTS --> DATA TYPES --> Variable-Type Memory Requirements.

Guest

Re: Memory

Post by Guest » Thu Nov 28, 2002 7:50 am

making a byte out ot a string is not a good Idea.

as you can see string*1 would take more than 1 byte because of the string descriptor which is 7 bytes long.

try this instead:

to put values:
A%=(Byte2%*256) or Byte1%

to get values:

Byte1%=A% and 255
Byte2%=A%\256

That way you could represent 2 bytes in one integer.

Guest

Re: Memory

Post by Guest » Tue Dec 03, 2002 8:15 pm

Thank you relsoft. Using strings to store switches instead of integers didn't sound right. Goes against anything I've ever worked with before. I'll experiment with your byte code... Thank you again.

Post Reply