[SOLVED] STM32F103ZE 64KB Memory depleted by String class array

Generic boards that are not Maple or Maple mini clones, and don't contain the additional USB reset hardware
User avatar
martinayotte
Posts: 1229
Joined: Mon Apr 27, 2015 1:45 pm

Re: STM32F103ZE 64KB Memory Handle Error

Post by martinayotte » Fri Sep 01, 2017 5:03 pm

Rick Kimball wrote:
Fri Sep 01, 2017 4:51 pm
I can't really imagine trying to use an array of Strings the way he has it coded. I'm guessing he meant to allocate one String instance that is 2170 bytes long.
Right ! I think you put the finger on it !
In many forums, I've seen some newbies that could not even distinguish the difference between a struct allocations and a pointers to structs, causing null pointer exceptions.

zmemw16
Posts: 1449
Joined: Wed Jul 08, 2015 2:09 pm
Location: St Annes, Lancs,UK

Re: STM32F103ZE 64KB Memory Handle Error

Post by zmemw16 » Fri Sep 01, 2017 5:16 pm

homework ?
commercial ?
srp

User avatar
martinayotte
Posts: 1229
Joined: Mon Apr 27, 2015 1:45 pm

Re: STM32F103ZE 64KB Memory Handle Error

Post by martinayotte » Fri Sep 01, 2017 5:20 pm

zmemw16 wrote:
Fri Sep 01, 2017 5:16 pm
homework ?
commercial ?
srp
What do you mean ?

zmemw16
Posts: 1449
Joined: Wed Jul 08, 2015 2:09 pm
Location: St Annes, Lancs,UK

Re: STM32F103ZE 64KB Memory Handle Error

Post by zmemw16 » Fri Sep 01, 2017 5:29 pm

student of somewhere seeking ready made solution, although they're generally more forthcoming with the details.
my normal response is a google search string :)
someone working on something commercial and trying not to give too much away - succeeding
or
someone yanking our chains
srp

User avatar
martinayotte
Posts: 1229
Joined: Mon Apr 27, 2015 1:45 pm

Re: STM32F103ZE 64KB Memory Handle Error

Post by martinayotte » Fri Sep 01, 2017 5:36 pm

Here is an example I found this morning ... :ugeek:
https://esp32.com/viewtopic.php?f=2&t=2870

victor_pv
Posts: 1681
Joined: Mon Apr 27, 2015 12:12 pm

Re: STM32F103ZE 64KB Memory Handle Error

Post by victor_pv » Fri Sep 01, 2017 8:19 pm

martinayotte wrote:
Fri Sep 01, 2017 5:36 pm
Here is an example I found this morning ... :ugeek:
https://esp32.com/viewtopic.php?f=2&t=2870
And we thought that some questions here didn't make sense...

gasparobr
Posts: 7
Joined: Tue Jan 17, 2017 4:15 pm

Re: STM32F103ZE 64KB Memory Handle Error

Post by gasparobr » Fri Sep 01, 2017 8:28 pm

Rick Kimball wrote:
Fri Sep 01, 2017 4:51 pm
Sometimes I wonder if people come in here and post questions just to troll us?

The original poster doesn't seem to be showing us the code that he is really running. So for us to try and figure out what he is doing is just a waste of time. I can't really imagine trying to use an array of Strings the way he has it coded. I'm guessing he meant to allocate one String instance that is 2170 bytes long.
Hi Rick. I don't want to troll u. My main code is running out of memory with no reason. So I just try to fill all the memory to see what happen. I DON'T USE THAT CODE, it a simplr sample to test the FULL user of memory.
Last edited by gasparobr on Fri Sep 01, 2017 9:02 pm, edited 1 time in total.

User avatar
Rick Kimball
Posts: 1038
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: STM32F103ZE 64KB Memory Handle Error

Post by Rick Kimball » Fri Sep 01, 2017 8:32 pm

Why don't you post that code then?
-rick

gasparobr
Posts: 7
Joined: Tue Jan 17, 2017 4:15 pm

Re: STM32F103ZE 64KB Memory Handle Error

Post by gasparobr » Fri Sep 01, 2017 8:58 pm

Rick Kimball wrote:
Fri Sep 01, 2017 8:32 pm
Why don't you post that code then?
My code has 9k lines of code. The code FREEZE without reason if I add any String or use Serial.print(); or Serial.print(F()), with just 23k of memory ALOCATED. I use a lot of SERIAL PROCESSOR in that code. That is the cause I did that sample code to test the RAM.

I did other test now with other sample and I can just use 23k of the RAM with String, but if I use other arrays of FLOAT and DOUBLE, I can use the full 64k.

Rick, I'm not expert of embedded processor, but I think the STM32DUINO is focus in our case, cause it help A LOT build embedded CODE without be a EXPERT.

Thanks for the attention!

User avatar
Rick Kimball
Posts: 1038
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: STM32F103ZE 64KB Memory Handle Error

Post by Rick Kimball » Fri Sep 01, 2017 9:11 pm

It is highly unlikely the problem is String. If you have 9k of code, that is a lot of lines of code that could be making the String function a look like a red herring.

Are you using an array of Strings or a single String and trying iterate though each item in the single String?

What does that 9k of code do?

Can you solve your problem not using String?

Do you understand how String works? Each String item allocates 12 bytes before you even put anything in it.

class String : {...
a buffer *
an int containing its capacity
an int containing its actual length.

4 bytes + 4bytes + 4bytes
}

When you actually put something into the String value it allocates more memory and sets the buffer pointer to that address. However, malloc does not ask for the exact number of characters you ask for. (Actually it uses realloc())

String mystring; // reserves 12 bytes in the .bss this is not available for heap or stack.

void somefunc() {
...
mystring = 'A'; // allocates 16 bytes from heap
...
}

The line of code above actually allocates at least 16 bytes because String it assumes you are going to grow the string
(Otherwise why wouldn't you be using some other data storage primitive) Also, malloc works better when it can allocate and free items of the same size.

So we don't actually know how you are using your String objects. Without seeing your code flow we can only guess.

Post Reply