malloc

malloc

Post by predato » Tue, 02 May 2000 04:00:00



Whan i locate mem with malloc i read thet that memory isne clered,how to
clera that
memory?
 
 
 

malloc

Post by Delon Nicola » Tue, 02 May 2000 04:00:00



> Whan i locate mem with malloc i read thet that memory isne clered,how to
> clera that
> memory?

i think you can use calloc, here is an example:

char *str;

instead of writing something like str = malloc(42 * sizeof(char))
you can write str = calloc(42, sizeof(char))
and the memory allocated will be full of "zero"

 
 
 

malloc

Post by Erik Max Franci » Tue, 02 May 2000 04:00:00



> i think you can use calloc, here is an example:

> char *str;

> instead of writing something like str = malloc(42 * sizeof(char))
> you can write str = calloc(42, sizeof(char))
> and the memory allocated will be full of "zero"

Note that this is not guaranteed to set pointers (say, if you're
calloc'ing a struct containing a pointer) to the null pointer, because
under Standard C there is no guarantee that the null pointer has the
internal representation of all bits zero.  In this case you'll have to
do an appropriate initialization, or a memberwise initialization to
zero.

--

  Alcyone Systems | web http://www.alcyone.com/max/ | 971.352 Ms p.L.
 San Jose, CA, US | icbm 37 20 N 121 53 W | 245 days left | &tSftDotIotE
__________________| Interstelen -- http://www.interstelen.com/
 __
/  \ I thought I might never see another Saturday night.
\__/ Robert Macnamara

 
 
 

malloc

Post by Tim Robbin » Fri, 05 May 2000 04:00:00


Use memset()...

#define SIZE 10
char* myblock;
if ((myblock = malloc(SIZE)) == NULL) abort();
memset (myblock, 0, SIZE);
/* do something with block */
free (myblock);

HTH,

Tim


Quote:> Whan i locate mem with malloc i read thet that memory isne clered,how to
> clera that
> memory?

 
 
 

1. C question : redefining a new malloc() calling standard malloc()

Hello,

I am currently writing, in C (on SGI IRIX 6.4), a redefinition of
malloc(), but I would like to still be able to call the standard library
malloc().

I am looking for a way to link the all properly !

I so have the four (+1) files :

* real_malloc.h : to call the standard library malloc()
---------------
#include <stdlib.h>

void* real_malloc(size_t);

* real_malloc.c
---------------
#include "real_malloc.h"

void* real_malloc(size_t size)
{
   /* Should call the standard library malloc() */
   return malloc(size);

* my_malloc.h : my redefinition of malloc()
-------------
#include <stdlib.h>

void* malloc(size_t);

* my_malloc.c
--------------
#include "my_malloc.h"
#include "real_malloc.h"

void* malloc(size_t size)
{
   /* some code */
   void* a = real_malloc(size);
   /* some code */

* essai.c : a test file
----------

#include "my_malloc.h"

main()
{
   /* should call my malloc redefinition */
   void* a = malloc(...);

How can I have the all correctly compile, link and WORK ???

Thanks for all response, comment, suggestion.

You can directly reply by mail.

---------------------
Xavier.

2. Firewire card for LinuxPPC

3. malloc problem ! Can malloc althought got 6 MB mem free !

4. TAR Problems

5. malloc() is weird

6. conditional Makefile

7. malloc == memory fragmentation

8. USENIX Annual Tech - Additions to Program and Savings Deadline is here

9. AIX malloc and fault tolerance - just the facts

10. Segfaults in malloc()

11. how get malloc to fail with swap space

12. malloc/free confuse me

13. zsh's malloc won't work!