Jump to content
Sign in to follow this  
fughilli

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?

 

Thanks!

 

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

Smoother.zip

Share this post


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!

 

Smoother.zip

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×