FACT++  1.0
MemoryNode* createMemoryNode ( unsigned int  size,
char  type,
char *  module,
unsigned int  preSize 
)

Definition at line 3732 of file feeserver.c.

References createLogMessage(), Memory::free(), lastMemoryNode, Memory::malloc(), size, sprintf(), and type.

Referenced by allocateMemory().

3733  {
3734 
3735  // check, if size is greater then preSize
3736  if (size <= preSize) {
3737  createLogMessage(MSG_ERROR,
3738  "Error: asking for memory smaller or equal than its prefix size.",
3739  0);
3740 # ifdef __DEBUG
3741  printf("Error: asking for memory smaller or equal than its prefix size.\n");
3742  fflush(stdout);
3743 # endif
3744  return 0;
3745  }
3746 
3747  MemoryNode* memNode = (MemoryNode*) malloc(sizeof(MemoryNode));
3748  if (memNode == 0) {
3749  // insufficient memory
3750  createLogMessage(MSG_ERROR,
3751  "Insufficient memory! Unable to allocate memory for MemoryNode.",
3752  0);
3753 # ifdef __DEBUG
3754  printf("Insufficient memory! Unable to allocate memory for MemoryNode.\n");
3755  fflush(stdout);
3756 # endif
3757  }
3758 
3759  // fill MemoryNode
3760  void* ptr = (void*) malloc(size);
3761  if (ptr == 0) {
3762  // insufficient memory
3763  char msg[100];
3764  msg[sprintf(msg,
3765  "Insufficient memory! Unable to allocate memory block of %d .",
3766  size)] = 0;
3767  createLogMessage(MSG_ERROR, msg, 0);
3768 # ifdef __DEBUG
3769  printf("Insufficient memory! Unable to allocate memory block of %d .\n",
3770  size);
3771  fflush(stdout);
3772 # endif
3773 
3774  free(memNode);
3775  return 0;
3776  }
3777 
3778  memNode->ptr = ptr;
3779  memNode->identityAddr = ptr + preSize;
3780  memNode->mmData.memSize = size;
3781  memNode->mmData.memType = type;
3782  if (module != 0) {
3783  strncpy(memNode->mmData.memDest, module, 30);
3784  memNode->mmData.memDest[29] = 0;
3785  } else {
3786  memNode->mmData.memDest[0] = 0;
3787  }
3788  if (preSize > 0) {
3789  memNode->mmData.prefixed = true;
3790  } else {
3791  memNode->mmData.prefixed = false;
3792  }
3793  memNode->mmData.prefixSize = preSize;
3794 
3795  // add Node to list (add at end)
3796  memNode->prev = lastMemoryNode;
3797  memNode->next = 0;
3798 
3799  if (lastMemoryNode != 0) {
3800  lastMemoryNode->next = memNode;
3801  }
3802  lastMemoryNode = memNode;
3803 
3804  if (firstMemoryNode == 0) {
3805  firstMemoryNode = memNode;
3806  }
3807 
3808  return memNode;
3809 }
static MemoryNode * lastMemoryNode
Definition: feeserver.c:322
void * malloc()
Definition: EventBuilder.cc:99
void createLogMessage(unsigned int type, char *description, char *origin)
Definition: feeserver.c:1530
int type
static MemoryNode * firstMemoryNode
Definition: feeserver.c:316
int size
Definition: db_dim_server.c:17
void free(void *mem)
sprintf(name1,"NewService%d", i)

+ Here is the call graph for this function:

+ Here is the caller graph for this function: