public inbox for rda@sourceware.org
 help / color / mirror / Atom feed
* Re: [RFA] rda/samples: improve memory allocation
@ 2004-07-10  3:26 Michael Elizabeth Chastain
  2004-07-12 23:50 ` Michael Snyder
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Elizabeth Chastain @ 2004-07-10  3:26 UTC (permalink / raw)
  To: binutils, cagney, gdb-patches, msnyder, rda

Michael Snyder writes:

  + #define ALLOC_UNIT  0x1000;

    Oops, extra semicolon!

  + #define alloc_roundup(LEN) ((LEN / ALLOC_UNIT) + ALLOC_UNIT)

    This looks like it's missing a multiplication again by ALLOC_UNIT.
    Say, if LEN is 0x3000, then alloc_roundup(LEN) comes out to 0x1003
    which seems weird.

Perhaps:

#define alloc_roundup(LEN) ((((LEN)+ALLOC_UNIT-1) / ALLOC_UNIT) * ALLOC_UNIT)

Or I dunno exactly what you want, but that definition doesn't look
right.  Looks like a missing call to alloc_coffee somewhere ...

Michael C

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFA] rda/samples: improve memory allocation
  2004-07-10  3:26 [RFA] rda/samples: improve memory allocation Michael Elizabeth Chastain
@ 2004-07-12 23:50 ` Michael Snyder
  0 siblings, 0 replies; 3+ messages in thread
From: Michael Snyder @ 2004-07-12 23:50 UTC (permalink / raw)
  To: Michael Elizabeth Chastain; +Cc: binutils, cagney, gdb-patches, rda

Michael Elizabeth Chastain wrote:
> Michael Snyder writes:
> 
>   + #define ALLOC_UNIT  0x1000;
> 
>     Oops, extra semicolon!
> 
>   + #define alloc_roundup(LEN) ((LEN / ALLOC_UNIT) + ALLOC_UNIT)
> 
>     This looks like it's missing a multiplication again by ALLOC_UNIT.
>     Say, if LEN is 0x3000, then alloc_roundup(LEN) comes out to 0x1003
>     which seems weird.
> 
> Perhaps:
> 
> #define alloc_roundup(LEN) ((((LEN)+ALLOC_UNIT-1) / ALLOC_UNIT) * ALLOC_UNIT)
> 
> Or I dunno exactly what you want, but that definition doesn't look
> right.  Looks like a missing call to alloc_coffee somewhere ...

Mmm, for some reason, I've always been roundup-challenged.
Withdrawn and re-submitted, with your suggestions.  Thanks.


[msnyder@dhcp-172-16-25-160 samples]$ make coffee
make: *** No rule to make target `coffee'.  Stop.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [RFA] rda/samples: improve memory allocation
@ 2004-07-09 21:39 Michael Snyder
  0 siblings, 0 replies; 3+ messages in thread
From: Michael Snyder @ 2004-07-09 21:39 UTC (permalink / raw)
  To: gdb-patches, rda, binutils, Andrew Cagney

[-- Attachment #1: Type: text/plain, Size: 173 bytes --]

Two problems with existing code:
1) Grows the simulated memory one byte at a time, and
2) If target_mem.base ever moves down, doesn't compensate
by moving the contents up.


[-- Attachment #2: diff5 --]
[-- Type: text/plain, Size: 2499 bytes --]

2004-07-09  Michael Snyder  <msnyder@redhat.com>

	* samples/demo-target.c (demo_set_thread_mem): Allocate new 
	simulated memory in hunks, rather than one byte at a time.
	If target_mem.base moves down, copy contents up.

Index: demo-target.c
===================================================================
RCS file: /cvs/cvsfiles/devo/rda/samples/demo-target.c,v
retrieving revision 1.19
diff -p -r1.19 demo-target.c
*** demo-target.c	21 Aug 2002 22:43:14 -0000	1.19
--- demo-target.c	9 Jul 2004 21:30:22 -0000
*************** demo_get_mem (struct gdbserv* serv, 
*** 385,390 ****
--- 385,393 ----
    return n;
  }
  
+ #define ALLOC_UNIT  0x1000;
+ #define alloc_roundup(LEN) ((LEN / ALLOC_UNIT) + ALLOC_UNIT)
+   
  
  static long
  demo_set_thread_mem (struct gdbserv *serv, 
*************** demo_set_thread_mem (struct gdbserv *ser
*** 398,420 ****
    gdbserv_reg_to_ulong (serv, addr, &request_base);
    if (target_mem.len == 0)
      {
!       target_mem.buf  = malloc (len);
!       target_mem.len  = len;
!       gdbserv_reg_to_ulong (serv, addr, &target_mem.base);
      }
    else
      {
        if (request_base < target_mem.base)
  	{
! 	  target_mem.len += target_mem.base - request_base;
  	  target_mem.base = request_base;
  	  target_mem.buf  = realloc (target_mem.buf, target_mem.len);
  	}
        if (request_base + len > 
  	  target_mem.base + target_mem.len)
  	{
! 	  target_mem.len += 
! 	    (request_base + len) - (target_mem.base + target_mem.len);
  	  target_mem.buf  = realloc (target_mem.buf, target_mem.len);
  	}
      }
--- 401,427 ----
    gdbserv_reg_to_ulong (serv, addr, &request_base);
    if (target_mem.len == 0)
      {
!       target_mem.len  = alloc_roundup (len);
!       target_mem.buf  = malloc (target_mem.len);
!       target_mem.base = request_base;
      }
    else
      {
        if (request_base < target_mem.base)
  	{
! 	  unsigned long oldlen = target_mem.len;
! 	  unsigned long movlen = target_mem.base - request_base;
! 
! 	  target_mem.len += alloc_roundup (target_mem.base - request_base);
  	  target_mem.base = request_base;
  	  target_mem.buf  = realloc (target_mem.buf, target_mem.len);
+ 	  memmove (target_mem.buf + movlen, target_mem.buf, oldlen);
  	}
        if (request_base + len > 
  	  target_mem.base + target_mem.len)
  	{
! 	  target_mem.len += alloc_roundup ((request_base + len) - 
! 					   (target_mem.base + target_mem.len));
  	  target_mem.buf  = realloc (target_mem.buf, target_mem.len);
  	}
      }

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-07-12 23:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-10  3:26 [RFA] rda/samples: improve memory allocation Michael Elizabeth Chastain
2004-07-12 23:50 ` Michael Snyder
  -- strict thread matches above, loose matches on Subject: below --
2004-07-09 21:39 Michael Snyder

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).