Exemple #1
0
void *sm_xmalloc(char *fname, int lineno, size_t size)
{
	void *buf;
	buf = sm_malloc(fname, lineno, size);
	if (buf == NULL) nomem(fname, lineno, size);
	return buf;
}
Exemple #2
0
POOLMEM *sm_get_pool_memory(const char *fname, int lineno, int pool)
{
   struct abufhead *buf;

   if (pool > PM_MAX) {
      Emsg2(M_ABORT, 0, _("MemPool index %d larger than max %d\n"), pool, PM_MAX);
   }
   P(mutex);
   if (pool_ctl[pool].free_buf) {
      buf = pool_ctl[pool].free_buf;
      pool_ctl[pool].free_buf = buf->next;
      pool_ctl[pool].in_use++;
      if (pool_ctl[pool].in_use > pool_ctl[pool].max_used) {
         pool_ctl[pool].max_used = pool_ctl[pool].in_use;
      }
      V(mutex);
      Dmsg3(dbglvl, "sm_get_pool_memory reuse %p to %s:%d\n", buf, fname, lineno);
      sm_new_owner(fname, lineno, (char *)buf);
      return (POOLMEM *)((char *)buf+HEAD_SIZE);
   }

   if ((buf = (struct abufhead *)sm_malloc(fname, lineno, pool_ctl[pool].size+HEAD_SIZE)) == NULL) {
      V(mutex);
      Emsg1(M_ABORT, 0, _("Out of memory requesting %d bytes\n"), pool_ctl[pool].size);
   }
   buf->ablen = pool_ctl[pool].size;
   buf->pool = pool;
   pool_ctl[pool].in_use++;
   if (pool_ctl[pool].in_use > pool_ctl[pool].max_used) {
      pool_ctl[pool].max_used = pool_ctl[pool].in_use;
   }
   V(mutex);
   Dmsg3(dbglvl, "sm_get_pool_memory give %p to %s:%d\n", buf, fname, lineno);
   return (POOLMEM *)((char *)buf+HEAD_SIZE);
}
Exemple #3
0
void *sm_realloc(const char *fname, int lineno, void *ptr, unsigned int size)
{
   unsigned osize;
   void *buf;
   char *cp = (char *) ptr;

   Dmsg4(DT_MEMORY|50, "sm_realloc %s:%d %p %d\n", get_basename(fname), (uint32_t)lineno, ptr, size);
   if (size <= 0) {
      e_msg(fname, lineno, M_ABORT, 0, _("sm_realloc size: %d\n"), size);
   }

   /*  If  the  old  block  pointer  is  NULL, treat realloc() as a
      malloc().  SVID is silent  on  this,  but  many  C  libraries
      permit this.  */
   if (ptr == NULL) {
      return sm_malloc(fname, lineno, size);
   }

   /* If the old and new sizes are the same, be a nice guy and just
      return the buffer passed in.  */
   cp -= HEAD_SIZE;
   struct abufhead *head = (struct abufhead *)cp;
   osize = head->ablen - (HEAD_SIZE + 1);
   if (size == osize) {
      return ptr;
   }

   /* Sizes differ.  Allocate a new buffer of the  requested  size.
      If  we  can't  obtain  such a buffer, act as defined in SVID:
      return NULL from  realloc()  and  leave  the  buffer  in  PTR
      intact.  */

// sm_buffers--;
// sm_bytes -= head->ablen;

   if ((buf = smalloc(fname, lineno, size)) != NULL) {
      memcpy(buf, ptr, (int)sm_min(size, osize));
      /* If the new buffer is larger than the old, fill the balance
         of it with "designer garbage". */
      if (size > osize) {
         memset(((char *) buf) + osize, 0x55, (int) (size - osize));
      }

      /* All done.  Free and dechain the original buffer. */
      sm_free(fname, lineno, ptr);
   }
   Dmsg4(DT_MEMORY|60, _("sm_realloc %d at %p from %s:%d\n"), size, buf, get_basename(fname), (uint32_t)lineno);
   return buf;
}
Exemple #4
0
void *b_malloc(const char *file, int line, size_t size)
{
  void *buf;

#ifdef SMARTALLOC
  buf = sm_malloc(file, line, size);
#else
  buf = malloc(size);
#endif
  if (buf == NULL) {
     berrno be;
     e_msg(file, line, M_ABORT, 0, _("Out of memory: ERR=%s\n"), be.bstrerror());
  }
  return buf;
}
Exemple #5
0
/* Get nonpool memory of size requested */
POOLMEM *sm_get_memory(const char *fname, int lineno, int32_t size)
{
   struct abufhead *buf;
   int pool = 0;

   if ((buf = (struct abufhead *)sm_malloc(fname, lineno, size+HEAD_SIZE)) == NULL) {
      Emsg1(M_ABORT, 0, _("Out of memory requesting %d bytes\n"), size);
   }
   buf->ablen = size;
   buf->pool = pool;
   buf->next = NULL;
   pool_ctl[pool].in_use++;
   if (pool_ctl[pool].in_use > pool_ctl[pool].max_used)
      pool_ctl[pool].max_used = pool_ctl[pool].in_use;
   return (POOLMEM *)(((char *)buf)+HEAD_SIZE);
}
int main(int argc, char** argv){
    int pid, total;
    
    sm_node_init(&argc, &argv, &total, &pid);

    char* crap;
    char* crap2;
    char* crap3;
    char* crap4;
    char* crap5;
    char* crap6;

    if (pid == 0){
        crap = sm_malloc(sizeof(char));
    }

    if (pid == 1){
        crap2 = sm_malloc(sizeof(char));
    }
    if (pid == 2){
        crap3 = sm_malloc(sizeof(char));
    }
    if (pid == 3){
        crap4 = sm_malloc(sizeof(char));
    }
    if (pid == 4){
        crap5 = sm_malloc(sizeof(char));
    }
    if (pid == 5){
        crap6 = sm_malloc(sizeof(char));
    }

    sm_bcast((void **) &crap,0);
    sm_bcast((void **) &crap2,1);
    sm_bcast((void **) &crap3,2);
    sm_bcast((void **) &crap4,3);
    sm_bcast((void **) &crap5,4);
    sm_bcast((void **) &crap6,5);

    sm_barrier();

    fprintf(stderr,"POINTER 1 %p, node %d\n",crap, pid);
    fprintf(stderr,"POINTER 2 %p, node %d\n",crap2, pid);
    fprintf(stderr,"POINTER 3 %p, node %d\n",crap3, pid);
    fprintf(stderr,"POINTER 4 %p, node %d\n",crap4, pid);
    fprintf(stderr,"POINTER 5 %p, node %d\n",crap5, pid);
	fprintf(stderr,"POINTER 6 %p, node %d\n",crap6, pid);

    sm_barrier();

    if (pid == 0){
        printf("ALLOCATED 0\n");
        *crap = '0';
        printf("CLIENTE CLIENTE CLIENTE CLIENTE 1 %p value %c\n",crap,*crap);
    }

    if (pid == 1){
        printf("ALLOCATED 1\n");
        *crap2 = '9';
        printf("CLIENTE CLIENTE CLIENTE CLIENTE 2 %p value %c\n",crap2,*crap2);
    }

    if (pid == 2){
        printf("ALLOCATED 1\n");
        *crap3 = '7';
        printf("CLIENTE CLIENTE CLIENTE CLIENTE 3 %p value %c\n",crap3,*crap3);
    }

    if (pid == 3){
        printf("ALLOCATED 1\n");
        *crap4 = '4';
        printf("CLIENTE CLIENTE CLIENTE CLIENTE 4 %p value %c\n",crap4,*crap4);
    }

    if (pid == 4){
        printf("ALLOCATED 1\n");
        *crap5 = '3';
        printf("CLIENTE CLIENTE CLIENTE CLIENTE 5 %p value %c\n",crap5,*crap5);
    }

    if (pid == 5){
        printf("ALLOCATED 1\n");
        *crap6 = '2';
        printf("CLIENTE CLIENTE CLIENTE CLIENTE 6 %p value %c\n",crap6,*crap6);
    }

    /*
*/  
//    sm_barrier();
//  while (1);
    sm_node_exit();
}
void * operator new(size_t size)
{
   return sm_malloc(__FILE__, __LINE__, size);
}
Exemple #8
0
void * operator new(size_t size)
{
// Dmsg1(000, "new called %d\n", size);
   return sm_malloc(__FILE__, __LINE__, size);
}