[Tremor] Memory Usage

Michael Smith mlrsmith at gmail.com
Tue Feb 1 16:25:29 PST 2005


On Tue, 1 Feb 2005 14:41:43 +0530, Ripinder Singh
<ripinder.singh at gmail.com> wrote:
> Hi,
> 
> I would like to mention some of the findings regarding heap size and
> data memory in general for tremor low_mem. I tried to compile the
> low_mem branch code on VC++ 6.0 and our host platform. As the host
> platform doesn't support alloca, I tried to fit the same with malloc
> and (subsequent) free calls. Incorporating the dyanamic memory from
> the heap only, I have received the following figures for the heap
> usage of Tremor. Although the heap variance may be more for some other
> songs, this is an estimate for song "sweet child" from GNR, encoded
> using winLame on different bitrates.
> 
> Stereo   64Kbps                             34603 Bytes
> Stereo   128Kbps                           35424 Bytes
> Stereo   500Kbps                           40184 Bytes
> Stereo   64-128( variable)Kbps         33874 Bytes
> Stereo   64-500( variable)Kbps         40184 Bytes
> 
> The stack usage for lowmem tremor branch is around 2KB and the
> Rom(Constant Data)  is around 46KB.
> 
> So far these estimates are pretty much better that that for WMA(64KB
> heap), given the doubts of greater heap usage due to non-fixed tables
> for huffman.

Thanks for going to the trouble to work up these numbers - I'm sure
lots of other people will find them useful. It's very much
appreciated!

> 
> Still some concerns in my mind reagrding the file codebook.c. In the
> function vorbis_book_unpack, why is the memory for variable s->val is
> put to NULL before returning from function. Is the assumption of
> alloca automatically freeing the memory used somehow. This I ask
> because I have to replace the alloca calls with a malloc and a free
> call at the end. If the value is lost, memory is explicitly not freed.
> Although I have applied a workaround still it would be nice if someone
> can explain the use of the procedure.

'alloca' does stack-based allocation. It's basically a way to (without
changing the base language - though it requires compiler support)
simulate variable size arrays (C99 has actual variable-size arrays,
but alloca() is much older).

Because they're allocated in the stack frame, they automatically
"disappear" as soon as the function that calls alloca() returns. So:
memory allocated by alloca() cannot be explicitly freed, but it's
always automatically freed when the function returns (or when the
stack frame goes out of scope, if that's sooner). So what the code is
doing is safe - but if you're having to replace alloca() with another
allocation strategy, you'll have to deal with this differently.


> 
> Also wouldn't it be nice if a set of reference input and outputs were
> provided with the source code as it would really help in
> standadization of the codec. And is there any compliance criterion
> defined for tremor ??

Yeah, it'd be good to have this sort of thing. We don't currently have
any reference samples, or compliance criteria. Would you be interested
in helping develop some of these?

Mike


More information about the Tremor mailing list