April 27, 2024, 05:04:19 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Possible problem with strings or is it me?

Started by Dennisc, January 03, 2007, 11:13:48 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Dennisc

January 03, 2007, 11:13:48 AM Last Edit: January 03, 2007, 12:22:58 PM by Dennisc
Hi
Not too sure if this is a possible string handling bug or whether it is something I am doing wrong. When the snippet is executed, each field shows the correct lengths. Once they are all set up, the lengths are all wrong. I have tried to  replace the SPACE$ with a STRING$ statement with the same effect. Commenting out individual "xxx = SPACE$...." statements does not sort the problem out. Perhaps the fields are being correctly initialised but that the LEN function might be giving problems.

I originally thought it might be the size of the strings but the manual states that ISTRING field sizes are limited only by memory and I recall Paul increasing the max size of strings - perhaps something slipped thru the enhancement?

Any help will be greatly appreciated. Busy writing a large app in EBasic and it has come to a grinding halt until I can resolve this...

Dennis
 


$MAIN
DEF prfActivities[1471]:ISTRING
DEF prfProblems[30151]:ISTRING
DEF prfEvents[8001]:ISTRING
DEF prfDefDocs[441]:ISTRING 
DEF prfPlanDocs[441]:ISTRING

OPENCONSOLE
PRINT "While Setting up"
PRINT " "

prfActivities = SPACE$(1471)
  PRINT "prfActivities ",LEN(prfActivities)

prfProblems = SPACE$(30151)
PRINT "prfProblems ",LEN(prfProblems)

prfEvents = SPACE$(8001)
PRINT "prfEvents ",LEN(prfEvents)

prfDefDocs = SPACE$(441)
PRINT "prfDefDocs ",LEN(prfDefDocs)

prfPlanDocs = SPACE$(441)
PRINT "prfPlanDocs ",LEN(prfPlanDocs)

PRINT "  "
PRINT "After setting up"
PRINT " "
PRINT "prfActivities ",LEN(prfActivities)
PRINT "prfProblems ",LEN(prfProblems)
PRINT "prfEvents ",LEN(prfEvents)
PRINT "prfDefDocs ",LEN(prfDefDocs) 
PRINT "prfPlanDocs ",LEN(prfPlanDocs)

DO:UNTIL INKEY$ <> ""
CLOSECONSOLE
END
Failure is only the opportunity to begin again more intelligently
www.denniscomninos.com

Dennisc

January 03, 2007, 11:55:35 AM #1 Last Edit: January 03, 2007, 12:22:00 PM by Dennisc
Tried replacing the SPACE$ statement with a loop to initialise the fields - same problem......

Dennis


$MAIN
DEF prfActivities[1471]:ISTRING
DEF prfProblems[30151]:ISTRING
DEF prfEvents[8001]:ISTRING
DEF prfDefDocs[441]:ISTRING 
DEF prfPlanDocs[441]:ISTRING
DEF i:int

OPENCONSOLE
PRINT "While Setting up"
PRINT " "

prfActivities = ""
FOR i=1 TO 1471
prfActivities = prfActivities + " "
NEXT i
  PRINT "prfActivities ",LEN(prfActivities)

prfProblems = ""
FOR i=1 TO 30151
prfProblems = prfProblems + " "
NEXT i
PRINT "prfProblems ",LEN(prfProblems)

prfEvents = ""
FOR i=1 TO 8001
prfEvents = prfEvents + " "
NEXT i
PRINT "prfEvents ",LEN(prfEvents)

prfDefDocs = ""
FOR i=1 TO 441
prfDefDocs = prfDefDocs + " "
NEXT i
PRINT "prfDefDocs ",LEN(prfDefDocs)

prfPlanDocs = ""
FOR i=1 TO 441
prfPlanDocs = prfPlanDocs + " "
NEXT i
prfPlanDocs = SPACE$(441)

PRINT "  "
PRINT "After setting up"
PRINT " "
PRINT "prfActivities ",LEN(prfActivities)
PRINT "prfProblems ",LEN(prfProblems)
PRINT "prfEvents ",LEN(prfEvents)
PRINT "prfDefDocs ",LEN(prfDefDocs) 
PRINT "prfPlanDocs ",LEN(prfPlanDocs)

DO:UNTIL INKEY$ <> ""
CLOSECONSOLE
END
Failure is only the opportunity to begin again more intelligently
www.denniscomninos.com

Dennisc

Still trying to figure out what's happening....

This works........


$MAIN
DEF d[30000]:ISTRING
d=SPACE$(30000)
openconsole
print len(d)
do:until inkey$<> ""
closeconsole
end


This doesn't..........


$MAIN
DEF d[30000]:ISTRING
DEF e[8000]:ISTRING
d=SPACE$(30000)
e=SPACE$(8000)
openconsole
print len(d)
print len(e)
do:until inkey$<> ""
closeconsole
end


Dennis
Failure is only the opportunity to begin again more intelligently
www.denniscomninos.com

Dennisc

OK, got it to work by increasing the field size in the DEF to larger than what the initialisation statement (SPACE$) sets. There must be a reason for it or something that I am misunderstanding about strings. Can someone give me an explanation?

Regards
Dennis
Failure is only the opportunity to begin again more intelligently
www.denniscomninos.com

mrainey

Is the terminating NULL referenced in the User Guide causing your problem - assigning 30000 spaces when there's only room for 29999?


"The STRING variable type is dimensioned automatically to 255 bytes which is enough room for 254 characters and the terminating NULL. The ISTRING variable type is unique to the Emergence BASIC language and can be dimensioned to create a string from 1 to the amount of available memory"
Software For Metalworking
http://closetolerancesoftware.com

Ionic Wind Support Team

All strings are NULL terminated.  You have to account for the NULL.  A string of 255 bytes is enough space for 254 characters and the terminator.

Ionic Wind Support Team

billhsln

January 03, 2007, 12:29:49 PM #6 Last Edit: January 03, 2007, 12:31:37 PM by billhsln
I am guessing that ISTRINGs need the "\0" (null) at the end to tell it where the end of the string is.  "\0" (Null) is the end of line indicator.  Maybe ISTRINGS need that Character.

I modified your program to only do 1 less than the length given and it works correctly.

Bill
When all else fails, get a bigger hammer.

Dennisc

Thanks Mike, Paul - it was obviously the NULL character. I originally set the DEF one bigger in my app to cater for it but it still caused a problem. I am sure now that it was me - it's late and I have been coding non-stop for the past 15 hours - became confused with all the numbers. Forgot about the NULL  :-[  :-[

Apologies for wasting everybody's time - need coffee and/or sleep....  ;D ;D

Regards
Dennis
Failure is only the opportunity to begin again more intelligently
www.denniscomninos.com

mrainey

Quoteneed coffee and/or sleep

Nah.  Try wine, women, and song.   ;D
Software For Metalworking
http://closetolerancesoftware.com

Dennisc

Mmmmmmmmmmmmm - variety is the spice of life (or so they say).....  ;D Will take your advice ......
Failure is only the opportunity to begin again more intelligently
www.denniscomninos.com

Rod

My doctor says I have to give up wine and women, but I can sing all I want to.

I said "If I give up wine and women, what's left to sing about?!"

;D

Dennisc

Too true!! Can't sing anyway so will stick to wine and women  ;D
Failure is only the opportunity to begin again more intelligently
www.denniscomninos.com

barry

I'd like a little clarification with respect to strings and arrays of strings.  I'm not talking about ISTRINGS, now.

STRING s[4000] seems to create an array of 4000 strings.  Are they internally an array of pointers to memory that will be allocated as needed for each string or are they pre-allocated at 256 bytes * 4000?  If I move 5 character strings into each string member of the array does that mean the other 250 bytes per string have been wasted?  Or are they allocated when something is moved into them and do I not have to worry about it?

If they are pre-allocated how can I save that space?

I realize that I don't have to care in terms of making it work but it's nice to know how to be efficient.

Thanks,
Barry

Ionic Wind Support Team

Defined global variables aren't allocated.  They are entries in the BSS section of the executable and Windows reserves that much memory when the executable is loaded.  Defined local variables exist on the stack and only use the memory when the subroutine is running, you have to have enough stack space to define it though.  4000*255 = 1MB. 

The default stack size is 32K which can be adjusted in the "advanced" section of the executable options (or project options) dialog.

So yes the answer to your question is it is all wasted space if you aren't using it.  However we are only talking about 1MB here and I wouldn't worry too much about it. 

Paul.

Ionic Wind Support Team

barry

QuoteHowever we are only talking about 1MB here and I wouldn't worry too much about it.

Actually I wasn't worried anyway.  I even went to sleep right after making that post.  It's just nice to know how things work.

Not worrying about 1 meg even seems like fun.  Like igniting hundred dollar bills to light a cigarette.  Live a little. :)

The first computer I worked on had 80k and 5 job slots (and was a very big computer at that time) and if I suggested to the boss that I could save 100 bytes but it might mean an extra day's programming, he'd jump at it!

But yeah, it's only 1 meg so why worry.

Barry