Jump to content

Issue with dynamic memory allocation and analogRead()

Recommended Posts

Hello everyone,


I've written a small library for smoothing raw data by averaging collected values over a set history, and to accomplish this in a portable way I made the "Smoother" class a template. There is an array of the generic T type that starts as a private pointer and is then allocated as an array using the "new" keyword of a size specified by the user.


Everything works fine and dandy on codepad.org, so I assumed I could just plop it down verbatim onto the Stellaris Launchpad. Unfortunately, the sample program I've written does not work as expected; instead, the analogRead() function spits out a bunch of gibberish values.


I figured this is some kind of memory allocation error, but it could be something completely different, so could anyone take a look at the source and maybe diagnose the problem/point me in the right direction?




P.S., I was able to get mixed results by instantiating the "Smoother" with the "SOLVE_ON_PUSH" flag set.


Link to post
Share on other sites

Well, after much deliberation and a while reading through documentation on C++ templates, I've (more or less) fixed my own problem. Instead of allocating memory dynamically, I've opted for a statically allocated Smoother instance using a template argument.


The new library is attached below. Any further suggestions would be greatly appreciated!



Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...