Menu

remove malloc from the code

2019-05-16
2019-11-15
  • Vaishali Patne

    Vaishali Patne - 2019-05-16

    I am working on hardware implemetation of MPC - from your suggestion to another post - I am able to remove all instances of calloc. but there are few more instances of malloc -
    Realvec = (typeRNum)malloc(size * sizeof(typeRNum));
    how to remove that - I dont have option of dynamic memory allocation.

     
  • Andreas Völz

    Andreas Völz - 2019-05-16

    Hello Vaishali,

    as far as I can see, the two functions CastDvec2Intvec and CastDvec2Numvec are not used within the C code (relevant folders are grampc/src and grampc/include). These functions are used in the Matlab interface and should therefore better be placed somewhere in grampc/matlab/src. For a hardware implementation, I would suggest to simply remove or comment these two functions.

    Regards,
    Andreas

     
  • Vaishali Patne

    Vaishali Patne - 2019-05-16

    Thanks Andreas
    will check the same.

    Also from file grampc_util.c
    cs = (typeInt )calloc(size, sizeof(typeInt))

    is creating variable soze array - is there any option for this?

    thanks in advance

     
  • Andreas Völz

    Andreas Völz - 2019-05-16

    Hello Vaishale,

    please see my comment in https://sourceforge.net/p/grampc/discussion/general/thread/73178797f2/. If you have some replacement for calloc on your hardware, there are very few instances of calloc that you have to replace. Otherwise, things are more involved. Basically, you have to fix some parameters of your problem (Nx, Nu, Np, Nhor, MaxGradIter, MaxMultIter), then you can replace all dynamically allocated arrays by fixed-size arrays. In the current version of GRAMPC, there is no support for generating this automatically, so you have to modify the code yourself.

    Regards,
    Andreas

     
  • Andreas Völz

    Andreas Völz - 2019-11-15

    Hello Vaishale,

    for your information, the new version 2.2 of GRAMPC supports compilation without dynamic memory allocation, i.e. without any calls to malloc, calloc or realloc. Please have a look at Section 5.1.5 of the updated documentation, where this new functionality is explained.

    Regards,
    Andreas

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.