True statement, but how do I determine this bound?
>
> >> >
> >>
> >>
> >>Hi there,
> >>
> >>I'm experimenting with dynamic storage allocation for hard real time
> >>embedded systems and I've come across two of interest: the Lea
> allocator
> >>and the TLSF allocator. Lea allocator as many of you probably know is
> one
> >>of the best out there but I couldn't find any information on using it
> in
> >>hard real time systems. But according to the internal documentation it
> >>has bounded operations. TLSF is specifically designed for real time
> and
> >>claims fast response times with worst case O(1) time for malloc and
> free.
> >>But in my own tests, it appears the Lea allocator outperforms TLSF.
> Has
> >>anyone used either and what are your thoughts?
> >
> >
> >I've not used either one, and generally use fixed-size buffer pools
> >when dynamic memory allocation is required in a real-time app. But I
> >have a couple observations.
> >
> >"O(1)" means (essentially) fixed cost. It doesn't mean that cost is
> >always 1.
> >
> >"Bounded" says the cost never exceeds a particular value. An O(1)
> >process is likewise "bounded" to the fixed cost
> >
> >If the average time for an Lea operation is 50, while the average time
> >for a TLSF is 100, then the Lea will "outperform" the TLSF. However,
> >if the upper bound on the Lea is 1000, the TLSF is 100, and your
> >application will not withstand any memory allocation operation longer
> >than 500, then the TLSF will be acceptable and the Lea will not. Fast
> >enough is fast enough, and too long is too long.
If I remember correctly, both Lea and TLSF put free blocks in "bins" based on size. Each bin corresponds to a range of sizes. For small blocks (up to 512 bytes I think), Lea puts only one size in each bin. But for larger sizes, there are multiple size blocks in each bin. Lea does a linear search of the bin for the best fit. So Lea is hard to beat if you only allocate small blocks, and slow (but good) for large blocks. TLSF never searches its bins for best fit, but the "wasted" space is limited to I think less than 2% or so of the block size.
This is an allocator I wrote that always does best-fit for any size block, but has O(log N) time complexity.
formatting link
I'd be curious to know how similar our approaches to allocator benchmarking are.
Have you seen this site with a TLSF allocator?
formatting link