|
From: Tom T. <Tom...@sa...> - 2007-03-22 20:04:02
|
Hi, I want to do malloc/free checking on some custom memory allocators,
and prefer to copy/adapt existing code than start from scratch.
Okay, I'm lazy. The doc on this is pretty basic,
and I would likely stumble several times before getting something =
usable.
So, is there a simple demo wrapper for custom malloc/free? E.g. for
void *mymalloc(size_t size, int who)
{
int32_t *p =3D malloc(16+size);
if (!p) return p;
*p =3D who;
return (void *)((char*)p + 16);
}
void myfree(void *ptr, int who)
{
int32_t *p =3D (char *)ptr - 16;
if (*p !=3D who) abort();
free(p);
}
Hopefully,
Tom Truscott
|
|
From: Julian S. <js...@ac...> - 2007-03-26 03:12:29
|
Tom
Valgrind's docs don't AFAIK offer any guidance on writing functions
in the style you show, and indeed these functions don't have anything
much to do with Valgrind/Memcheck, unless I misunderstand. So I'm not
sure what it is you're trying to achieve. Can you clarify?
J
On Thursday 22 March 2007 20:03, Tom Truscott wrote:
> Hi, I want to do malloc/free checking on some custom memory allocators,
> and prefer to copy/adapt existing code than start from scratch.
>
> Okay, I'm lazy. The doc on this is pretty basic,
> and I would likely stumble several times before getting something usable.
>
> So, is there a simple demo wrapper for custom malloc/free? E.g. for
>
> void *mymalloc(size_t size, int who)
> {
> int32_t *p = malloc(16+size);
> if (!p) return p;
> *p = who;
> return (void *)((char*)p + 16);
> }
>
> void myfree(void *ptr, int who)
> {
> int32_t *p = (char *)ptr - 16;
> if (*p != who) abort();
> free(p);
> }
>
> Hopefully,
> Tom Truscott
>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share
> your opinions on IT & business topics through brief surveys-and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Valgrind-users mailing list
> Val...@li...
> https://lists.sourceforge.net/lists/listinfo/valgrind-users
|
|
From: Nicholas N. <nj...@cs...> - 2007-03-26 04:20:55
|
On Mon, 26 Mar 2007, Julian Seward wrote:
> Valgrind's docs don't AFAIK offer any guidance on writing functions
> in the style you show, and indeed these functions don't have anything
> much to do with Valgrind/Memcheck, unless I misunderstand. So I'm not
> sure what it is you're trying to achieve. Can you clarify?
I think he has those two functions below in his program, and he wants
to write function wrappers for them. But it's not easy to tell from the
original email.
Nick
> On Thursday 22 March 2007 20:03, Tom Truscott wrote:
>> Hi, I want to do malloc/free checking on some custom memory allocators,
>> and prefer to copy/adapt existing code than start from scratch.
>>
>> Okay, I'm lazy. The doc on this is pretty basic,
>> and I would likely stumble several times before getting something usable.
>>
>> So, is there a simple demo wrapper for custom malloc/free? E.g. for
>>
>> void *mymalloc(size_t size, int who)
>> {
>> int32_t *p = malloc(16+size);
>> if (!p) return p;
>> *p = who;
>> return (void *)((char*)p + 16);
>> }
>>
>> void myfree(void *ptr, int who)
>> {
>> int32_t *p = (char *)ptr - 16;
>> if (*p != who) abort();
>> free(p);
>> }
>>
>> Hopefully,
>> Tom Truscott
>>
>> -------------------------------------------------------------------------
>> Take Surveys. Earn Cash. Influence the Future of IT
>> Join SourceForge.net's Techsay panel and you'll get the chance to share
>> your opinions on IT & business topics through brief surveys-and earn cash
>> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
>> _______________________________________________
>> Valgrind-users mailing list
>> Val...@li...
>> https://lists.sourceforge.net/lists/listinfo/valgrind-users
>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys-and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Valgrind-users mailing list
> Val...@li...
> https://lists.sourceforge.net/lists/listinfo/valgrind-users
>
|