This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: Does nano-malloc support target without unaligned load/store instructions?
- From: Can Finner <can dot finner at gmail dot com>
- To: Pei-Shiang Hung <pshung807 at gmail dot com>
- Cc: "newlib at sourceware dot org" <newlib at sourceware dot org>, Joey Ye <Joey dot Ye at arm dot com>
- Date: Fri, 22 Jan 2016 10:08:20 +0000
- Subject: Re: Does nano-malloc support target without unaligned load/store instructions?
- Authentication-results: sourceware.org; auth=none
- References: <CAPfXio96ST3S4GezSkGR_dufDz5UJVj7+bjuFMKJa1b-B2PPag at mail dot gmail dot com>
On Fri, Jan 22, 2016 at 9:14 AM, Pei-Shiang Hung <pshung807@gmail.com> wrote:
> In nano-mallocr.c,
> 262 while (r)
> 263 {
> 264 int rem = r->size - alloc_size;
> 265 if (rem >= 0)
> 266 {
> 267 if (rem >= MALLOC_MINCHUNK)
> 268 {
> 269 /* Find a chunk that much larger than required size, break
> 270 * it into two chunks and return the second one */
> 271 r->size = rem;
> 272 r = (chunk *)((char *)r + rem);
> 273 r->size = alloc_size;
> 274 }
>
> line 272, it is dangerous to cast 'r' to 'char *', plus 'rem', then
> cast back to 'chunk *'. What if the given 'rem' is not a word-aligned
> number? It can cause unaligned access exception. (This does happen in
> my application.)
>
> So, does nano-malloc be designed for specific target with unaligned
> memory access instructions only(eg. ARM)?
>
>
> Thanks all.
Suppose we can support that with a little bit memory cost? CCing Joey
about this.
Thanks,
bin
--
Regards.