RAM size problems
Posted: Sun Sep 03, 2017 6:58 pm
I wrote a small program and the RAM memory was unexpected full, so I tried the causes.
I did some simple tests, insert or remove instances and check the size of the compiled program.
This helps me understand how the functions I want to use lie in the memory space of the CPU. The processor I use
has little/normal memory eeprom / ram.
I can not understand how the compiler handles some instances of strings.
This is a test that anyone can do
// Cpu PIB18LF14K22 (Ran 512 Bytes)
// Test String
Public Dim MyStr As String
case 1) I do not use MyStr, compiling -> success: 1613 Program Bytes Used, 300 Variable Bytes Used, OK!
case 2) Add instruction in the my program:
MyStr = "abcd",
compiling -> success: 1637 PBU / 324 VBU -> Increase of 24PBU / 24VBU Bytes, that's right?
case 3) then reduce the string content to a single character
MyStr = "a",
compiling -> success: 1635 PBU / 350 VBU -> Increase of 22 PBU / 50 VBU Bytes, why it goes to 50 Bytes instead of staying at 24 Bytes?
// Test USART
Public Dim MyStr As String
case 1) I do not use MyStr,
compiling -> success: 1613 Program Bytes Used, 300 Variable Bytes Used, OK!
case 2) Add instruction in the my program:
MyStr = FloatToStr(sin(10))
usart.write((MyStr), 13, 10)
compiling -> success: 4757 PBU / 397 VBU -> Increase of 3144 PBU / 97 50 VBU Bytes, the "FloatToString" + "sin" functions cost me so much (maybe just the first time I use these?)
case 3) instead of the two instructions I put one, the following
Write(FloatToStr(sin(10)), 13, 10)
Surprise:
compiling -> success: 4795 PBU / 510 VBU -> higher increase of 3182 PBU / 210 VBU, but why?
With these prerogatives how I can use my CPU with 512 Bytes, two instructions like this and the program will override the RAM.
Maybe I'm stupid but please help me to understand,
thank you in advance
Umberto
I did some simple tests, insert or remove instances and check the size of the compiled program.
This helps me understand how the functions I want to use lie in the memory space of the CPU. The processor I use
has little/normal memory eeprom / ram.
I can not understand how the compiler handles some instances of strings.
This is a test that anyone can do
// Cpu PIB18LF14K22 (Ran 512 Bytes)
// Test String
Public Dim MyStr As String
case 1) I do not use MyStr, compiling -> success: 1613 Program Bytes Used, 300 Variable Bytes Used, OK!
case 2) Add instruction in the my program:
MyStr = "abcd",
compiling -> success: 1637 PBU / 324 VBU -> Increase of 24PBU / 24VBU Bytes, that's right?
case 3) then reduce the string content to a single character
MyStr = "a",
compiling -> success: 1635 PBU / 350 VBU -> Increase of 22 PBU / 50 VBU Bytes, why it goes to 50 Bytes instead of staying at 24 Bytes?
// Test USART
Public Dim MyStr As String
case 1) I do not use MyStr,
compiling -> success: 1613 Program Bytes Used, 300 Variable Bytes Used, OK!
case 2) Add instruction in the my program:
MyStr = FloatToStr(sin(10))
usart.write((MyStr), 13, 10)
compiling -> success: 4757 PBU / 397 VBU -> Increase of 3144 PBU / 97 50 VBU Bytes, the "FloatToString" + "sin" functions cost me so much (maybe just the first time I use these?)
case 3) instead of the two instructions I put one, the following
Write(FloatToStr(sin(10)), 13, 10)
Surprise:
compiling -> success: 4795 PBU / 510 VBU -> higher increase of 3182 PBU / 210 VBU, but why?
With these prerogatives how I can use my CPU with 512 Bytes, two instructions like this and the program will override the RAM.
Maybe I'm stupid but please help me to understand,
thank you in advance
Umberto