Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 19:51 27 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : MMBasic 4.4 Beta 1

     Page 3 of 3    
Author Message
James_From_Canb

Senior Member

Joined: 19/06/2011
Location: Australia
Posts: 265
Posted: 10:11pm 31 May 2013
Copy link to clipboard 
Print this post

  Geoffg said   So,

1. who has run out of memory because of strings?

2. Secondly, would it be OK if fixed length strings were only implemented in arrays with different arrays allowed to have different sizes?

3. And a third question, would an option at the beginning of the program to set the string size for all strings be better?

Speak up!

Geoff


1. I ran out of memory when I wrote the RENUMBER program. Chaining fixed the code space problem, and deleting my string arrays after use freed up memory. I was also careful to declare variables as Local in subroutines and functions if they were local to the routines. Once I did that I had no more memory problems.

2. Sounds good.

3. That sounds good too. I rarely use long strings, but I do use big multi-dimensional arrays of small strings. Having the option to reduce the maximum size of strings would help.

The important thing is that I was able to write my program using the options you have already provided. Reducing the string size would have allowed me to fit more code into memory and reduced the need for chaining which would have been more convenient, but it it wasn't too difficult to work around.

James
My mind is aglow with whirling, transient nodes of thought careening through a cosmic vapor of invention.

Hedley Lamarr, Blazing Saddles (1974)
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 11:31pm 31 May 2013
Copy link to clipboard 
Print this post

  shoebuckle said  
  TZAdvantage said   Defining the fixed length of the string would need some extra syntax.
I think the use of square brackets is the most terse:
STATIC B$[100] 'one string with fixed length = 100
It is a bit strange ( I could get used to it :) ) when used in combination with an array:
STATIC B$(100)[20] '100 string of fixed length 20


To be consistent with parameters on other commands, perhaps a comma would be better than square brackets. e.g. DIM a$(2,10),10 to define an array with elements 10 characters long. Making the length spec optional would make the command backward compatible.
Cheers,
Hugh

The added ,10 is indeed another way to do it.
The square brackets though stand out more and make it clear it is a length.
The square brackets should be optional too. If not used then a normal 256 byte string should be created to maintain backward compatibility.

Another way of declaring fixed length string as used in other basic is:
DIM strName AS STRING * n

This syntax is a lot different then the one chosen in MMBasic and only Geoff knows which way would be better to implement.

Edited by TZAdvantage 2013-06-02
Microblocks. Build with logic.
 
kiiid

Guru

Joined: 11/05/2013
Location: United Kingdom
Posts: 671
Posted: 11:43pm 31 May 2013
Copy link to clipboard 
Print this post

I think in his example Hugh has given the definition of a two-dimensional array with 10-character strings. There is an optional ",10" extension after the closing bracket. This format is really the most consistent with BASIC way to go for strings.

The question however is what does the string length represent - the maximum number of useful characters in a string, or the maximum number of useful characters PLUS an ending NUL character?

It won't be a good idea to have the maximum strings length defined at the top. BASIC is known for its easy string operations and anything like that would only move it towards C style, which the BASIC is not.


Edited by kiiid 2013-06-02
http://rittle.org

--------------
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 11:52pm 31 May 2013
Copy link to clipboard 
Print this post

Kid, i caught the ,10 the second time i read it and edited my post at the same time you made yours i think.
I am not in favor of the added ,10 as it is against all the normal practices when defining variables. I am conditioned (brainwashed ha ha) after too many years reading and writing basic and C(#).
I guess i think it is too subtle and invites errors. The square brackets are very obvious (when you first see it it will give you a 'Huh what is that feeling'), and i think that is a good thing. Fixed strings is 'against' normal basic practices but in environments with low amounts of memory or interfacing with the hardware it is a good addition.

MMBasic does not use an ending NUL character. It uses a pascal type string where the length is in the front followed by the content.
As such it should define the number of characters you can store in that string.

Edited by TZAdvantage 2013-06-02
Microblocks. Build with logic.
 
Juri74

Senior Member

Joined: 06/02/2012
Location: Italy
Posts: 162
Posted: 09:10am 03 Jun 2013
Copy link to clipboard 
Print this post

  Geoffg said  So, who has run out of memory because of strings?

Secondly, would it be OK if fixed length strings were only implemented in arrays with different arrays allowed to have different sizes?

And a third question, would an option at the beginning of the program to set the string size for all strings be better?

Speak up!

Geoff


Hello Geoff

1) i run out of memory on almost all program i made, first time i used arrays of strings then i switched back to arrays of numbers, and made my work associating a number to a series of strings.

2) Yes!

3) i think that an option at the beginning of program would be useful, 99% times i use strings in arrays, and 99% times i use strings not in arrays they are long max 1 line of screen..

eventually i use longer strings but because i know that a string is long 255 so i try to take full advantage of it..


little off topic:
is there a chance in the future that a pair of (i think) useful commands will be implemented?

i mean INC(variable) and DEC(variable) and in their extended format INC(variable,min,max) and ofcourse DEC(variable,max,min)
this could be stupid but it could replace a piece of code and run faster

i actually use functions for the job


Function INC(v,min,max)
v=v+1:if v>max then v=min
if v<min then v=min
inc=v:end function

Function DEC(v,min,max)
v=v-1:if v<min then v=max
if v>max then v=max
dec=v:end function


usage Variable=INC(Variable,min,max) and Variable=DEC(Variable,min,max)

example

value=INC(value,10,30)
lives=DEC(lives,0,99)

Juri
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3194
Posted: 11:26am 03 Jun 2013
Copy link to clipboard 
Print this post

OK, it looks as if being able to specify a string length is needed. This will be a a very large job and may take some time.

Your INC/DEC functions are neat but really the way that they should be implemented is as user defined functions - as you have already done. The only advantage in adding them to the language is that you would shave off a few microseconds but as I said before in this thread, any new additions need to deliver real value.

Geoff
Geoff Graham - http://geoffg.net
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6100
Posted: 01:23pm 03 Jun 2013
Copy link to clipboard 
Print this post

  Juri74 said  

Hello Geoff

1) i run out of memory on almost all program i made, first time i used arrays of strings then i switched back to arrays of numbers, and made my work associating a number to a series of strings.

2) Yes!

3) i think that an option at the beginning of program would be useful, 99% times i use strings in arrays, and 99% times i use strings not in arrays they are long max 1 line of screen..

eventually i use longer strings but because i know that a string is long 255 so i try to take full advantage of it..

Juri


Juri,
I posted a method of using short strings a while ago.
It might be useful for your programs.

http://www.thebackshed.com/forum/forum_posts.asp?TID=5236&KW =short+string

Jim


VK7JH
MMedit   MMBasic Help
 
     Page 3 of 3    
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024