![]() |
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: SwedenPosts: 104 |
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: AustraliaPosts: 1021 |
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: SwedenPosts: 104 |
OK. Do U now or What is the size of "pre-allocated vartbl"? /Peter63 |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10387 |
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: SwedenPosts: 104 |
OK thanks for explaining how it works. /Peter63 |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |