taskrambler  0.1.8
Web server and task management solution.
memory.h File Reference
#include <sys/types.h>
+ Include dependency graph for memory.h:

Go to the source code of this file.

Macros

#define CSTRA(val)   val, sizeof(val)-1
 Const STRing Argument. More...
 
#define MEM_FREE(seg)   (memFree((void **)&(seg)))
 

Functions

void * memMalloc (size_t)
 
void * memCalloc (size_t, size_t)
 
void memFree (void **)
 
size_t memGetSize (void *)
 
void memCleanup ()
 

Detailed Description

Author
Georg Hopp

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file memory.h.

Macro Definition Documentation

Function Documentation

void* memCalloc ( size_t  nmemb,
size_t  size 
)

this is a really memory wasting solution....just to be able to use calloc, which might be faster then malloc/memset solution.

Maybe this is a bad idea, as we need to memset the buffer anyway if it comes from our tree, which hopefully should be the majority of cases.

Definition at line 818 of file memory.c.

References memMalloc(), and size.

Referenced by applicationCtor(), applicationSessionCleanup(), classClone(), classNewParams(), hash_pw(), httpMessageCtor(), httpResponseCtor(), and serverCtor().

819 {
820  size_t _size = nmemb * size;
821  void * mem = memMalloc(_size);
822 
823  memset(mem, 0, _size);
824 
825  return mem;
826 }
void * memMalloc(size_t size)
Definition: memory.c:783
static size_t size

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void memCleanup ( )

Definition at line 862 of file memory.c.

References post(), and segmentFree().

Referenced by main().

863 {
864 #ifdef MEM_OPT
866 #endif
867 }
struct memSegment * segments
Definition: memory.c:756
void post(struct memSegment *tree, void(*cb)(struct memSegment *, int))
Definition: memory.c:666
static void segmentFree(struct memSegment *segment, int depth)
Definition: memory.c:760

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void memFree ( void **  )

Definition at line 829 of file memory.c.

References insertElement(), and memSegment::ref_count.

830 {
831  if (NULL != *mem) {
832  struct memSegment * seg = (*mem - sizeof(struct memSegment));
833 
834  if (1 < seg->ref_count) {
835  seg->ref_count--;
836  } else {
837 #ifdef MEM_OPT
838  insertElement(&segments, seg);
839 #else
840  free(seg);
841 #endif
842  }
843 
844  *mem = NULL;
845  }
846 }
struct memSegment * segments
Definition: memory.c:756
size_t ref_count
Definition: memory.c:62
struct memSegment * insertElement(struct memSegment **tree, struct memSegment *element)
Definition: memory.c:246

+ Here is the call graph for this function:

size_t memGetSize ( void *  )

Definition at line 849 of file memory.c.

References memSegment::size.

Referenced by httpWriterWrite().

850 {
851  struct memSegment * segment;
852 
853  if (NULL == mem) {
854  return 0;
855  }
856 
857  segment = (struct memSegment *)(mem - sizeof(struct memSegment));
858  return segment->size;
859 }
size_t size
Definition: memory.c:63

+ Here is the caller graph for this function:

void* memMalloc ( size_t  )

Definition at line 783 of file memory.c.

References deleteElement(), findElement(), newElement(), memSegment::ptr, and size.

Referenced by authLdapCtor(), cbufCtor(), configCtor(), configValueCtor(), controllerCurrentuserRead(), controllerLocRead(), controllerRandvalRead(), controllerSessinfoRead(), controllerUserRead(), controllerVersionRead(), credentialCtor(), hashValueCtor(), httpCookieCtor(), httpHeaderCtor(), httpParserHeader(), httpParserParse(), httpParserRequestVars(), httpRequestCtor(), httpResponse404(), httpResponse500(), httpResponseJson(), httpWorkerCtor(), httpWriterWrite(), loggerLog(), memCalloc(), newEle(), storageCtor(), storageGet(), userCtor(), userSerialize(), and userUnserialize().

784 {
785  struct memSegment * seg = NULL;
786  //long psize = sysconf(_SC_PAGESIZE);
787  long psize = 64;
788 
789  size += sizeof(struct memSegment);
790 
791  /* allocate only blocks of a multiple of pagesize, similar to cbuf */
792  size = (0>=size)?1:(0!=size%psize)?(size/psize)+1:size/psize;
793  size *= psize;
794 
795 #ifdef MEM_OPT
796  seg = findElement(segments, size);
797 #endif
798 
799  if (NULL == seg) {
800  seg = newElement(size);
801  } else {
802  // remove the found one from the tree as we use it now.
803  seg = deleteElement(&segments, seg);
804  }
805 
806  return seg->ptr;
807 }
void * ptr
Definition: memory.c:64
struct memSegment * deleteElement(struct memSegment **tree, struct memSegment *element)
Definition: memory.c:389
static size_t size
struct memSegment * newElement(size_t size)
Definition: memory.c:77
struct memSegment * segments
Definition: memory.c:756
struct memSegment * findElement(struct memSegment *tree, size_t size)
Definition: memory.c:100

+ Here is the call graph for this function:

+ Here is the caller graph for this function: