Re: [cc65] mallocing an aligned buffer

Date view Thread view Subject view

From: Ullrich von Bassewitz (uz_at_musoftware.de)
Date: 2003-01-28 17:35:26


Hi!

On Thu, Jan 23, 2003 at 08:54:05AM -0800, Shawn Jefferson wrote:
> Allocate a buffer that is 16 bytes extra then 7680, 4k aligned and then free
> the first 16 bytes.  Return a pointer to the start of the buffer + 16 bytes
> and that should give me the proper aligned buffer I need.
>
> Anything look wrong with this, or is there a better way to do this, assuming
> I want to support arbitrary screen line lengths (for large scrolling screens.)

Sounds good for me. The only problem is that you cannot free parts of a chunk
allocated by malloc, at least not using standard C calls. What you can do is
to use _hadd() to add a block to the heap free list, but this is non portable
(and probably not worth the trouble for just 16 bytes - the call to _hadd
will also need a few bytes).

Regards


        Uz


-- 
Ullrich von Bassewitz                                  uz_at_musoftware.de
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo_at_musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.


Date view Thread view Subject view

This archive was generated by hypermail 2.1.3 : 2003-01-28 17:36:24 CET