C++ Template Class Too Big for non-eXternal MM?
Syncrosis
Posts: 3
Hi everybody,
I'm trying to create a templated class in C++ for a generic linked list. I am stubbing in the framework for the templated class. Working incrementally, I put in the basics and instantiated an instance of the object. Upon calling the most basic of member functions, the compiler begins to complain at me about exceeding the hub .text region. I'm attempting to build to CMM. I'd like to steer away from XMM if possible - the only real external memory I have access to is an SD card and can't figure out how to load to it. Oh yea, I am not including any standard C++ libraries (at least not on purpose).
Here's my code reduced down, but still overflowing .text. Do you have any suggestions to reduce the binary size?
Thank you so much!
I'm trying to create a templated class in C++ for a generic linked list. I am stubbing in the framework for the templated class. Working incrementally, I put in the basics and instantiated an instance of the object. Upon calling the most basic of member functions, the compiler begins to complain at me about exceeding the hub .text region. I'm attempting to build to CMM. I'd like to steer away from XMM if possible - the only real external memory I have access to is an SD card and can't figure out how to load to it. Oh yea, I am not including any standard C++ libraries (at least not on purpose).
Here's my code reduced down, but still overflowing .text. Do you have any suggestions to reduce the binary size?
#include <stdio.h> // Recommended over iostream for saving space #include <propeller.h> // Propeller-specific functions typedef struct list_s { void *data; struct list_s *prev; struct list_s *next; } list_t; template <class T> class LinkList { private: list_t *front, *back; int size; public: LinkList(); int Enqueue(T *newObj); }; //default class constructor template <class T> LinkList<T>::LinkList() { size = 0; front = back = NULL; } template <class T> int LinkList<T>::Enqueue(T *newObj) { list_t *newNode = new list_t; if(newNode == NULL) return false; return true; } int main(){ LinkList<int> bob; int a = 42; bob.Enqueue(&a); return 0; }
Thank you so much!
Comments
Using templates in themselves should not generate any code over what you would get for a normal definition of the class for the types you are using.
I'm no great shakes at templates but that use of a typedef'ed structure seems all wrong.
Also that "void *data" cannot be right. Surely the idea of using a template is to have a type for the data you are storing in the list and to be able to instanciate lists for different types via templates.
My approach would be to get a normal linked list class working first. Test and debug that. Then apply templating to it.
No typedf stucts and no void* .
Here is a compile command example that follows the guidelines in the wiki.
propeller-elf-c++ -o cmm/templates.elf -Os -mcmm -Wall -m32bit-doubles -fno-exceptions -Dprintf=__simple_printf -fno-rtti templates.cpp
Template: https://github.com/libpropeller/libpropeller/blob/master/libpropeller/streaminterface/streaminterface.h
SD: https://github.com/libpropeller/libpropeller/blob/master/libpropeller/sd/sd.h
Serial: https://github.com/libpropeller/libpropeller/blob/master/libpropeller/serial/serial.h
I and others made a few posts in this thread discussing related topics: http://forums.parallax.com/showthread.php/150860-Pure-Virtual-Functions-Cause-Instant-Code-Bloat?p=1221449&viewfull=1#post1221449