Shop OBEX P1 Docs P2 Docs Learn Events
could we optimize abdrive.h — Parallax Forums

could we optimize abdrive.h

laurent974laurent974 Posts: 77
edited 2017-02-26 19:59 in Learn with BlocklyProp
Why abdrive.c include some header for string and text ?
#include "simpletools.h"
#include "simpletext.h"
#include <string.h>

could those be safely removed ?

Comments

  • simpletools.h File Reference
    This library provides convenient functions for a variety of microcontroller I/O, timing, conversion, and communication tasks. This library also includes (and you can call functions from) simpletext and serial. More...

    #include <propeller.h>
    #include "simpletext.h"
    #include <driver.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <cog.h>
    #include <ctype.h>
    #include <unistd.h>
    #include <sys/stat.h>
    #include <dirent.h>
    #include <sys/sd.h>
    #include <math.h>
    #include "simplei2c.h"
  • my concern is that my code don't use any string output. i don't use the terminal indeed.
    So i would like to save a few memory to get rid of the string.h or simpletext.h.

    anyway, abdrive is only for encoders or servo drive. it should not be about text.
  • Just an observation Laurent but to "like" to save memory is not normally a pressing reason. Memory is there to be used, not to be saved, and only if you get to the point where memory is being fully utilized then more than likely you would be utilizing simpletext anyway. The Propeller has 8 cogs and your application mightn't even use half of them etc but they come with the package, same with the libs.
  • laurent974 wrote: »
    my concern is that my code don't use any string output. i don't use the terminal indeed.
    So i would like to save a few memory to get rid of the string.h or simpletext.h.

    anyway, abdrive is only for encoders or servo drive. it should not be about text.

    I like your way of thinking and you are right there.

    abdrive should not need them headers, except if some constants or debug stuff is in there.

    but you do not need to worry, because PropGCC does not include all of this into your created binary for the propeller, just stuff you USE in your code.

    Enjoy!

    Mike


  • Using #include doesn't create code or take space, it just declares that some things exist "somewhere else", and specifies the format for those things. The linker is the part that takes all the libraries and your code, figures out what is actually used, and discards the rest. If you don't use the SimpleText functions, you will not end up with that code in your program, even if you include the headers.
  • TorTor Posts: 2,010
    As Jason said. Including header files won't increase memory usage. It's only information for the compiler. The exception would be if somebody put C code into a header file, which is something no C programmer should do. You won't find any C code in those header files included by simpletools.h
  • Even if there is code in header files (inline functions are really the only excuse for this), the functions there still won't take up any space if they aren't used.
Sign In or Register to comment.