Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 10:06 08 Sep 2025 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 : Using PRINT MM.INFO(HEAP) , when CONST is used

Author Message
Peter63
Senior Member

Joined: 28/07/2017
Location: Sweden
Posts: 104
Posted: 05:48am 23 Jul 2025
Copy link to clipboard 
Print this post

It seems that HEAP is calculated a bit incorrectly when CONST is used. See program example.
If the CONST string is longer than 16 characters, 256 bytes are allocated, but if it is 15 characters long, no change to the HEAP

'
' constants test program, 2025-07-23 Peter63
'
OPTION EXPLICIT
OPTION DEFAULT NONE

print mm.info(heap) ' 187648

const x1="123456789012345" ' 15 char = heap no changes
'const x1="1234567890123456" ' 16 char = heap changes to 187392
const x2="123456789012345"
const x3="123456789012345"
const x4="123456789012345"
const x5="123456789012345"
const x6="123456789012345"
const x7="123456789012345"
const x8="123456789012345"
const x9="123456789012345"
const x10="123456789012345"
const x11="123456789012345"
const x12="123456789012345"
const x13="123456789012345"
const x14="123456789012345"
const x15="123456789012345"
const x16="123456789012345"
const x17="123456789012345"
const x18="123456789012345"
const x19="123456789012345"
const x20="123456789012345"
const x21="123456789012345"
const x22="123456789012345" ' no change heap if all const is 15 char...???

print mm.info(heap) ' 187648
END




I use: PicoMiteHDMI MMBasic USB RP2350A Edition V6.00.03

/Peter63
Edited 2025-07-23 15:49 by Peter63
 
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 1021
Posted: 06:12am 23 Jul 2025
Copy link to clipboard 
Print this post

This is correct. A constant string < 16 characters is stored inside the MMBasic firmware pre-allocated vartbl, so does not need any heap memory. As soon as it is 16 or more characters it needs to use the heap, which is allocated in 256 byte chunks.
F4 H7FotSF4xGT
 
Peter63
Senior Member

Joined: 28/07/2017
Location: Sweden
Posts: 104
Posted: 06:21am 23 Jul 2025
Copy link to clipboard 
Print this post

OK. Do U now or What is the size of "pre-allocated vartbl"?

/Peter63
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10387
Posted: 07:37am 23 Jul 2025
Copy link to clipboard 
Print this post

For the RP2350 the firmware creates a hash table for the variables. This has 768 slots available, each slot is 64 bytes to include the variable name (32 bytes), the dimensions (5 * 4-byte integers), 4 status bytes, and the actual value or a pointer to the heap used (8 bytes).
In the case of strings, they are normally in heap which is allocated in 256 byte chunks, but there is an optimisation for short strings less than 16 characters which utilise the last 5 integers in the dimensions space in the vartbl.
 
Peter63
Senior Member

Joined: 28/07/2017
Location: Sweden
Posts: 104
Posted: 07:51am 23 Jul 2025
Copy link to clipboard 
Print this post

OK thanks for explaining how it works.
/Peter63
 
Print this page


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

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025