LD_PRELOADing malloc y gratis

Yo escribi mi propiaMalloc ygratis y los compilé en una biblioteca compartida. Yo LD_PRELOAD esa biblioteca con mi programa. De esta manera mi programa siempre usaría mi costumbre.Malloc ygratis o hay casos donde no es así. He oído que gcc ha construido en malloc ygratis también. ¿Es posible que el glibc que vino con mi gcc esté usando el builtin?Malloc ygratis.

En segundo lugar, observo que cuando ejecuto mi programa, estoy viendo elgratis función llamada más a menudo que lamalloc / calloc Llamadas (98 a 16). Yo no hago ninguna asignación de memoria (excepto en un lugar), por lo que toda la asignación se realiza mediante las funciones de biblioteca estándar que utilizo. Y también tenga en cuenta que estoy usando pthread en mi programa. Si quieres saber, mi programa se ve así.

#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/types.h>

#define NUM_THREADS     8

pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;

int sum;
float total = 1;
extern int __did_libc_start_main;

void *PrintHello(void *threadid)
{
   long tid;
   tid = (long)threadid;
   pthread_mutex_lock( &m );
   sum++;
   total *= total + tid * 0.097891313423578;
   printf( "p%d, tid%d, total = %g, start = %d!\n", getpid(), tid, total, 0 );
   pthread_mutex_unlock( &m );
   printf("Hello World! It's me, thread #%ld!\n", tid);
   pthread_exit(NULL);
}

int main (int argc, char *argv[])
{
   pthread_t threads[NUM_THREADS];
   int rc;
   long t;
   char * p;
   char * m;

   fork();

   p = (char*)mmap(0, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
   p[0] = 78;
   printf( "p = %p, p[0] = %d, pid = %d!\n", p, p[0], getpid() );
   m = (char*)malloc( 80 );
   printf( "m = %p!\n", m );
#if 1  
   for(t=0; t<NUM_THREADS; t++)
   {
      printf("In main: creating thread %ld\n", t);
      rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t);
      if (rc){
         printf("ERROR; return code from pthread_create() is %d\n", rc);
         exit(-1);
      }
   }
   for(t=0; t<NUM_THREADS; t++)
    pthread_join(threads[t], NULL);

   printf( "\n\nTotal = %g\n\n", total );

   /* Last thing that main() should do */
   pthread_exit(NULL);
#endif
   printf( "\n\n%d: Done without major problems\n\n", getpid() );
   return 0;
}

Respuestas a la pregunta(1)

Su respuesta a la pregunta