Memory allocation improvements

This pull requests fixes #5 and adds support to get statistics of current memory usage.