Go Down

Topic: [Published on GitHub] LinkedList Class (Fully implemented) (Read 16352 times) previous topic - next topic

robtillaart

quick guess(not dived into the code details)
- not allocating the stringA? and therefore reusing the same buffer over and over again?
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

PaulS

Code: [Select]
  string = (char *)malloc(sizeof(char *)*1024);
  stringA = (char *)malloc(sizeof(char *)*1024);
  temp = (char *)malloc(sizeof(char *)*1024);

Which Arduino are you expecting to be able to allocate 3072 bytes of SRAM on? Not a 328-based Arduino with 2048 bytes of SRAM.
The art of getting good answers lies in asking good questions.

khristopheryan


khristopheryan

#18
Feb 22, 2014, 04:03 am Last Edit: Feb 22, 2014, 04:07 am by khristopheryan Reason: 1
Quote
quick guess(not dived into the code details)
- not allocating the stringA? and therefore reusing the same buffer over and over again?


I don't think that is the problem because all the nodes in the linked list are changed with the value of the new node inserted. If it's using the same buffer over and over again, isn't it that the value of all the nodes will be the value of the first node stored in the list?

pYro_65


Code: [Select]
  string = (char *)malloc(sizeof(char *)*1024);
  stringA = (char *)malloc(sizeof(char *)*1024);
  temp = (char *)malloc(sizeof(char *)*1024);

Which Arduino are you expecting to be able to allocate 3072 bytes of SRAM on? Not a 328-based Arduino with 2048 bytes of SRAM.


I didn't notice it at first either, but the allocations above actually reserve 6144 bytes. (sizeof( char* ) == 2).
Forum Mod anyone?
https://arduino.land/Moduino/

PaulS

Hmmm. I missed that, too. It also means that the cast up front should be (char **), not (char *). That means that the variable type is wrong, too.
The art of getting good answers lies in asking good questions.

ivanseidel

I think that you should be allocating memory for the string everytime you create a new one, otherwise you will just be overriding it, and all values in the IP struct inside the LinkedList, will ref. the same pointer.

And also, alocating more than the arduino can, can cause it to crash  :smiley-eek:

If that doesn't work, I can try it here (without arduino right now...)
Arduino DueTimer | https://github.com/ivanseidel/DueTimer
Arduino Thread | https://github.com/ivanseidel/ArduinoThread

DemoManta

Thank you ivanseidel  for making this code public domain.

Yeah!  Someone who actually gets that you cannot use GPL and LGPL embedded code in a commercial project!

I found other list like libraries that are licensed either GPL or LGPL.  Basically they are useless to me because of my application.  For something at home they would be fine, but for anything else they are useless.

I write open source code and have released a few projects mostly for hobbies.  I always release under MIT for this reason.  If I am giving code away I want people to use it!  The only reason I do MIT is for CYA.

Again, thank you!  You saved me having to write my own list. 

Go Up