ucommon  7.0.0
About: GNU uCommon C++ is a portable and optimized class framework for writing C++ applications that need to use threads and support concurrent synchronization, and that use sockets, XML parsing, object serialization, thread-optimized string and data structure classes, etc..
  Fossies Dox: ucommon-7.0.0.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

memory.cpp
Go to the documentation of this file.
1 // Copyright (C) 2006-2014 David Sugar, Tycho Softworks.
2 // Copyright (C) 2015 Cherokees of Idaho.
3 //
4 // This file is part of GNU uCommon C++.
5 //
6 // GNU uCommon C++ is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU Lesser General Public License as published
8 // by the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // GNU uCommon C++ is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with GNU uCommon C++. If not, see <http://www.gnu.org/licenses/>.
18 
19 #include <ucommon-config.h>
20 #include <ucommon/export.h>
21 #include <ucommon/object.h>
22 #include <ucommon/memory.h>
23 #include <ucommon/thread.h>
24 #include <ucommon/string.h>
25 #include <ucommon/fsys.h>
26 #ifdef HAVE_UNISTD_H
27 #include <unistd.h>
28 #endif
29 #include <limits.h>
30 #include <string.h>
31 #include <stdio.h>
32 
33 #ifdef HAVE_STDALIGN_H
34 #include <stdalign.h>
35 #endif
36 
37 #if defined(_MSC_VER) && _MSC_VER >= 1800
38 #include <malloc.h>
39 #ifndef HAVE_ALIGNED_ALLOC
40 #define HAVE_ALIGNED_ALLOC 1
41 #endif
42 #define aligned_alloc(a, s) _aligned_malloc(s, a)
43 #endif
44 
45 namespace ucommon {
46 
47 extern "C" {
48 
49  static int ncompare(const void *o1, const void *o2)
50  {
51  assert(o1 != NULL);
52  assert(o2 != NULL);
53  const StringPager::member * const *n1 = static_cast<const StringPager::member * const*>(o1);
54  const StringPager::member * const *n2 = static_cast<const StringPager::member * const*>(o2);
55  return String::collate((*n1)->get(), (*n2)->get());
56  }
57 }
58 
60 {
62  pagesize = source.pagesize;
63  align = source.align;
64  count = source.count;
65  page = source.page;
66  limit = source.limit;
67  source.count = 0;
68  source.page = NULL;
69 }
70 
72 {
73 #ifdef HAVE_SYSCONF
74  size_t paging = sysconf(_SC_PAGESIZE);
75 #elif defined(PAGESIZE)
76  size_t paging = PAGESIZE;
77 #elif defined(PAGE_SIZE)
78  size_t paging = PAGE_SIZE;
79 #else
80  size_t paging = 1024;
81 #endif
82  if(!ps)
83  ps = paging;
84  else if(ps > paging)
85  ps = (((ps + paging - 1) / paging)) * paging;
86 
87 #if defined(HAVE_POSIX_MEMALIGN) || defined(HAVE_ALIGNED_ALLOC)
88  if(ps >= paging)
89  align = sizeof(void *);
90  else
91  align = 0;
92 
93  switch(align)
94  {
95  case 2:
96  case 4:
97  case 8:
98  case 16:
99  break;
100  default:
101  align = 0;
102  }
103 #endif
104  pagesize = ps;
105  count = 0;
106  limit = 0;
107  page = NULL;
108 }
109 
111 {
112  count = 0;
113  limit = 0;
114  page = NULL;
115  pagesize = copy.pagesize;
116  align = copy.align;
117 }
118 
120 {
121  memalloc::purge();
122 }
123 
124 unsigned memalloc::utilization(void) const
125 {
126  unsigned long used = 0, alloc = 0;
127  page_t *mp = page;
128 
129  while(mp) {
130  alloc += (unsigned long)pagesize;
131  used += mp->used;
132  mp = mp->next;
133  }
134 
135  if(!used)
136  return 0;
137 
138  alloc /= 100;
139  used /= alloc;
140  return used;
141 }
142 
143 void memalloc::purge(void)
144 {
145  page_t *next;
146  while(page) {
147  next = page->next;
148 #if defined(HAVE_ALIGNED_ALLOC) && defined(_MSWINDOWS_)
149  if (align)
150  _aligned_free(page);
151  else
152  free(page);
153 #else
154  free(page);
155 #endif
156  page = next;
157  }
158  count = 0;
159 }
160 
162 {
163  page_t *npage = NULL;
164 #ifdef HAVE_POSIX_MEMALIGN
165  void *addr;
166 #endif
167 
168  if(limit && count >= limit) {
169  __THROW_RUNTIME("pager exhausted");
170  return NULL;
171  }
172 
173 #if defined(HAVE_POSIX_MEMALIGN)
174  if(align && !posix_memalign(&addr, align, pagesize))
175  npage = (page_t *)addr;
176  else
177  npage = (page_t *)malloc(pagesize);
178 #elif defined(HAVE_ALIGNED_ALLOC)
179  if (align)
180  npage = (page_t *)aligned_alloc(align, pagesize);
181  else
182  npage = (page_t *)malloc(pagesize);
183 #else
184  npage = (page_t *)malloc(pagesize);
185 #endif
186 
187  if(!npage) {
188  __THROW_ALLOC();
189  return NULL;
190  }
191 
192  ++count;
193  npage->used = sizeof(page_t);
194  npage->next = page;
195  page = npage;
196  if((size_t)(npage) % sizeof(void *))
197  npage->used += sizeof(void *) - ((size_t)(npage) % sizeof(void
198 *));
199  return npage;
200 }
201 
202 void *memalloc::_alloc(size_t size)
203 {
204  assert(size > 0);
205 
206  caddr_t mem;
207  page_t *p = page;
208 
209  if(size > (pagesize - sizeof(page_t))) {
210  __THROW_SIZE("Larger than pagesize");
211  return NULL;
212  }
213 
214  while(size % sizeof(void *))
215  ++size;
216 
217  while(p) {
218  if(size <= pagesize - p->used)
219  break;
220  p = p->next;
221  }
222  if(!p)
223  p = pager();
224 
225  mem = ((caddr_t)(p)) + p->used;
226  p->used += (unsigned)size;
227  return mem;
228 }
229 
230 mempager::mempager(size_t ps) :
231 memalloc(ps)
232 {
233  pthread_mutex_init(&mutex, NULL);
234 }
235 
237 memalloc(copy)
238 {
239  pthread_mutex_init(&mutex, NULL);
240 }
241 
243 {
244  memalloc::purge();
245  pthread_mutex_destroy(&mutex);
246 }
247 
248 void mempager::_lock(void)
249 {
250  pthread_mutex_lock(&mutex);
251 }
252 
254 {
255  pthread_mutex_unlock(&mutex);
256 }
257 
258 unsigned mempager::utilization(void)
259 {
260  unsigned long used;
261 
262  pthread_mutex_lock(&mutex);
263  used = memalloc::utilization();
264  pthread_mutex_unlock(&mutex);
265  return used;
266 }
267 
268 void mempager::purge(void)
269 {
270  pthread_mutex_lock(&mutex);
271  memalloc::purge();
272  pthread_mutex_unlock(&mutex);
273 }
274 
275 void mempager::dealloc(void *mem)
276 {
277 }
278 
279 void *mempager::_alloc(size_t size)
280 {
281  assert(size > 0);
282 
283  void *mem;
284  pthread_mutex_lock(&mutex);
285  mem = memalloc::_alloc(size);
286  pthread_mutex_unlock(&mutex);
287  return mem;
288 }
289 
291 {
292  pthread_mutex_lock(&source.mutex);
293  pthread_mutex_lock(&mutex);
294  memalloc::assign(source);
295  pthread_mutex_unlock(&mutex);
296  pthread_mutex_unlock(&source.mutex);
297 }
298 
299 
301 LinkedObject(root)
302 {
303  mem = NULL;
304 }
305 
307 LinkedObject()
308 {
309  mem = NULL;
310 }
311 
312 ObjectPager::ObjectPager(size_t objsize, size_t size) :
313 memalloc(size)
314 {
315  members = 0;
316  root = NULL;
317  last = NULL;
318  index = NULL;
319  typesize = objsize;
320 }
321 
323 {
324  members = source.members;
325  root = source.root;
326  last = source.last;
327  index = source.index;
328  typesize = source.typesize;
329 
330  memalloc::assign(source);
331 
332  source.members = 0;
333  source.root = NULL;
334  source.last = NULL;
335  source.index = NULL;
336 }
337 
338 void *ObjectPager::get(unsigned ind) const
339 {
341 
342  if(ind >= members)
343  return invalid();
344 
345  while(ind--)
346  list.next();
347 
348  return list->mem;
349 }
350 
352 {
353  memalloc::purge();
354  members = 0;
355  root = NULL;
356  last = NULL;
357  index = NULL;
358 }
359 
360 void *ObjectPager::pull(void)
361 {
362  if(!members)
363  return invalid();
364 
365  member *mem = (member *)root;
366  void *result = mem->mem;
367  --members;
368  if(!members) {
369  root = NULL;
370  last = NULL;
371  }
372  else
373  root = mem->Next;
374  index = NULL;
375  return result;
376 }
377 
378 void *ObjectPager::push(void)
379 {
380  void *mem = memalloc::_alloc(sizeof(member));
381 
382  member *node;
383 
384  node = new(mem) member(&root);
385  if (!node)
386  return NULL;
387  if(!last)
388  last = node;
389  ++members;
390  node->mem = memalloc::_alloc(typesize);
391  index = NULL;
392  return node->mem;
393 }
394 
395 void *ObjectPager::pop(void)
396 {
397  void *out = NULL;
398 
399  if(!root)
400  return invalid();
401 
402  index = NULL;
403 
404  if(root == last) {
405  out = last->mem;
406  root = last = NULL;
407  members = 0;
408  return out;
409  }
410 
412  while(is(np)) {
413  if(np->Next == last) {
414  out = last->mem;
415  last = *np;
416  np->Next = NULL;
417  --members;
418  break;
419  }
420  np.next();
421  }
422  return out;
423 }
424 
425 void *ObjectPager::invalid(void) const
426 {
427  return NULL;
428 }
429 
430 void *ObjectPager::add(void)
431 {
432  void *mem = memalloc::_alloc(sizeof(member));
433  member *node;
434 
435  index = NULL;
436  if(members++) {
437  node = new(mem) member();
438  last->set(node);
439  }
440  else
441  node = new(mem) member(&root);
442  last = node;
443  node->mem = memalloc::_alloc(typesize);
444  return node->mem;
445 }
446 
447 void **ObjectPager::list(void)
448 {
449  void **dp = index;
450  if(dp)
451  return dp;
452 
453  unsigned pos = 0;
454  index = (void **)memalloc::_alloc(sizeof(void *) * (members + 1));
456  while(is(mp)) {
457  index[pos++] = mp->mem;
458  mp.next();
459  }
460  index[pos] = NULL;
461  return index;
462 }
463 
464 StringPager::member::member(LinkedObject **root, const char *data) :
465 LinkedObject(root)
466 {
467  text = data;
468 }
469 
470 StringPager::member::member(const char *data) :
471 LinkedObject()
472 {
473  text = data;
474 }
475 
477 memalloc(size)
478 {
479  members = 0;
480  root = NULL;
481  last = NULL;
482  index = NULL;
483 }
484 
486 {
487  members = source.members;
488  root = source.root;
489  last = source.last;
490  index = source.index;
491 
492  memalloc::assign(source);
493 
494  source.members = 0;
495  source.root = NULL;
496  source.last = NULL;
497  source.index = NULL;
498 }
499 
500 StringPager::StringPager(char **list, size_t size) :
501 memalloc(size)
502 {
503  members = 0;
504  root = NULL;
505  last = NULL;
506  add(list);
507 }
508 
509 bool StringPager::filter(char *buffer, size_t size)
510 {
511  add(buffer);
512  return true;
513 }
514 
515 unsigned StringPager::token(const char *text, const char *list, const char *quote, const char *end)
516 {
517  unsigned count = 0;
518  const char *result;
519  char *lastp = NULL;
520 
521  if(!text || !*text)
522  return 0;
523 
524  strdup_t tmp = strdup(text);
525  while(NULL != (result = String::token(tmp, &lastp, list, quote, end))) {
526  ++count;
527  add(result);
528  }
529  return count;
530 }
531 
532 String StringPager::join(const char *prefix, const char *middle, const char *suffix)
533 {
534  string_t tmp;
535 
536  if(!members)
537  return tmp;
538 
539  if(prefix && *prefix)
540  tmp += prefix;
541 
543  while(is(mp)) {
544  tmp += mp->text;
545  if(mp->Next && middle && *middle)
546  tmp += middle;
547  else if(mp->Next == NULL && suffix && *suffix)
548  tmp += suffix;
549  mp.next();
550  }
551 
552  return tmp;
553 }
554 
555 unsigned StringPager::split(const char *text, const char *string, unsigned flags)
556 {
557  strdup_t tmp = String::dup(string);
558  char *match = tmp;
559  char *prior = tmp;
560  size_t tcl = strlen(text);
561  unsigned count = 0;
562  bool found = false;
563 
564  // until end of string or end of matches...
565  while(prior && *prior && match) {
566 #if defined(_MSWINDOWS_)
567  if((flags & 0x01) == String::INSENSITIVE)
568  match = strstr(prior, text);
569 #elif defined(HAVE_STRICMP)
570  if((flags & 0x01) == String::INSENSITIVE)
571  match = stristr(prior, text);
572 #else
573  if((flags & 0x01) == String::INSENSITIVE)
574  match = strcasestr(prior, text);
575 #endif
576  else
577  match = strstr(prior, text);
578 
579  if(match)
580  found = true;
581 
582  // we must have at least one match to add trailing data...
583  if(match == NULL && prior != NULL && found) {
584  ++count;
585  add(prior);
586  }
587  // if we have a current match see if anything to add in front of it
588  else if(match) {
589  *match = 0;
590  if(match > prior) {
591  ++count;
592  add(prior);
593  }
594 
595  prior = match + tcl;
596  }
597  }
598  return count;
599 }
600 
601 void StringPager::set(unsigned ind, const char *text)
602 {
604 
605  if(ind >= members)
606 
607  while(ind--)
608  list.next();
609 
610  size_t size = strlen(text) + 1;
611  char *str = (char *)memalloc::_alloc(size);
612 #ifdef HAVE_STRLCPY
613  strlcpy(str, text, size);
614 #else
615  strcpy(str, text);
616 #endif
617  list->text = str;
618 }
619 
620 const char *StringPager::get(unsigned ind) const
621 {
623 
624  if(ind >= members) {
625  __THROW_RANGE("stringpager outside range");
626  return NULL;
627  }
628 
629  while(ind--)
630  list.next();
631 
632  return list->get();
633 }
634 
636 {
637  memalloc::purge();
638  members = 0;
639  root = NULL;
640  last = NULL;
641  index = NULL;
642 }
643 
644 const char *StringPager::pull(void)
645 {
646  if(!members) {
647  __THROW_RUNTIME("no members");
648  return NULL;
649  }
650 
651  member *mem = (member *)root;
652  const char *result = mem->text;
653  --members;
654  if(!members) {
655  root = NULL;
656  last = NULL;
657  }
658  else
659  root = mem->Next;
660  index = NULL;
661  return result;
662 }
663 
664 void StringPager::push(const char *text)
665 {
666  if(!text)
667  text = "";
668 
669  size_t size = strlen(text) + 1;
670  void *mem = memalloc::_alloc(sizeof(member));
671  char *str = (char *)memalloc::_alloc(size);
672 
673 #ifdef HAVE_STRLCPY
674  strlcpy(str, text, size);
675 #else
676  strcpy(str, text);
677 #endif
678  member *node;
679 
680  node = new(mem) member(&root, str);
681  if(!last)
682  last = node;
683  ++members;
684  index = NULL;
685 }
686 
687 const char *StringPager::pop(void)
688 {
689  const char *out = NULL;
690 
691  if(root == nullptr) {
692  __THROW_RUNTIME("no root");
693  return NULL;
694  }
695 
696  index = NULL;
697 
698  if(root == last) {
699  out = last->text;
700  root = last = NULL;
701  members = 0;
702  return out;
703  }
704 
706  while(is(np)) {
707  if(np->Next == last) {
708  out = last->text;
709  last = *np;
710  np->Next = NULL;
711  --members;
712  break;
713  }
714  np.next();
715  }
716  return out;
717 }
718 
719 void StringPager::add(const char *text)
720 {
721  if(!text)
722  text = "";
723 
724  size_t size = strlen(text) + 1;
725  void *mem = memalloc::_alloc(sizeof(member));
726  char *str = (char *)memalloc::_alloc(size);
727 
728 #ifdef HAVE_STRLCPY
729  strlcpy(str, text, size);
730 #else
731  strcpy(str, text);
732 #endif
733  member *node;
734 
735  index = NULL;
736  if(members++) {
737  node = new(mem) member(str);
738  last->set(node);
739  }
740  else
741  node = new(mem) member(&root, str);
742  last = node;
743 }
744 
745 void StringPager::set(char **list)
746 {
747  clear();
748  add(list);
749 }
750 
751 void StringPager::push(char **list)
752 {
753  const char *cp;
754  unsigned ind = 0;
755 
756  if(!list)
757  return;
758 
759  while(NULL != (cp = list[ind++]))
760  push(cp);
761 }
762 
763 void StringPager::add(char **list)
764 {
765  const char *cp;
766  unsigned ind = 0;
767 
768  if(!list)
769  return;
770 
771  while(NULL != (cp = list[ind++]))
772  add(cp);
773 }
774 
776 {
777  if(!members)
778  return;
779 
780  unsigned count = members;
781  member **list = new member*[members];
782  unsigned pos = 0;
784 
785  while(is(mp) && count--) {
786  list[pos++] = *mp;
787  mp.next();
788  }
789 
790  qsort(static_cast<void *>(list), members, sizeof(member *), &ncompare);
791  root = NULL;
792  while(pos)
793  list[--pos]->enlist(&root);
794 
795  delete[] list;
796  index = NULL;
797 }
798 
799 char **StringPager::list(void)
800 {
801  if(index)
802  return index;
803 
804  unsigned pos = 0;
805  index = (char **)memalloc::_alloc(sizeof(char *) * (members + 1));
807  while(is(mp)) {
808  index[pos++] = (char *)mp->text;
809  mp.next();
810  }
811  index[pos] = NULL;
812  return index;
813 }
814 
816 StringPager()
817 {
818  dir = NULL;
819 }
820 
822 {
823  dir = source.dir;
824  StringPager::assign(source);
825  source.dir = NULL;
826 }
827 
828 DirPager::DirPager(const char *path) :
829 StringPager()
830 {
831  dir = NULL;
832  load(path);
833 }
834 
835 bool DirPager::filter(char *fname, size_t size)
836 {
837  if(*fname != '.')
838  add(fname);
839  return true;
840 }
841 
842 void DirPager::operator=(const char *path)
843 {
844  dir = NULL;
845  clear();
846  load(path);
847 }
848 
849 bool DirPager::load(const char *path)
850 {
851  dir_t ds;
852  char buffer[128];
853 
854  if(!fsys::is_dir(path))
855  return false;
856 
857  dir = dup(path);
858  ds.open(path);
859  if(!ds)
860  return false;
861 
862  while(ds.read(buffer, sizeof(buffer)) > 0) {
863  if(!filter(buffer, sizeof(buffer)))
864  break;
865  }
866 
867  ds.close();
868  sort();
869  return true;
870 }
871 
873 {
874  pool = NULL;
875 }
876 
878 {
879  release();
880 }
881 
883 {
884  LinkedObject *obj;
885 
886  while(pool) {
887  obj = pool;
888  pool = obj->getNext();
889  obj->release();
890  }
891 }
892 
894 {
895  assert(obj != NULL);
896 
897  obj->enlist(&pool);
898 }
899 
902 {
903 }
904 
906 {
908  LinkedObject::Next = NULL;
909 }
910 
912 {
913  pager->put(this);
914 }
915 
917 {
919 }
920 
922 {
924 }
925 
927 {
928  freelist = NULL;
929  pthread_mutex_init(&mutex, NULL);
930 }
931 
933 {
934  pthread_mutex_destroy(&mutex);
935 }
936 
938 {
939  assert(ptr != NULL);
940 
941  pthread_mutex_lock(&mutex);
942  ptr->enlist(&freelist);
943  pthread_mutex_unlock(&mutex);
944 }
945 
947 {
948  assert(size > 0);
949 
950  PagerObject *ptr;
951  pthread_mutex_lock(&mutex);
952  ptr = static_cast<PagerObject *>(freelist);
953  if(ptr)
954  freelist = ptr->Next;
955 
956  pthread_mutex_unlock(&mutex);
957 
958  if(!ptr)
959  ptr = new((_alloc(size))) PagerObject;
960  else
961  ptr->reset();
962  if (ptr)
963  ptr->pager = this;
964  return ptr;
965 }
966 
967 } // namespace ucommon
ucommon::DirPager::operator=
void operator=(const char *path)
Definition: memory.cpp:842
ucommon::mempager
Definition: memory.h:184
ucommon::PagerPool::put
void put(PagerObject *object)
Definition: memory.cpp:937
ucommon::ObjectPager::size
size_t size(void)
Definition: memory.h:373
ucommon::memalloc::mempage
Definition: memory.h:69
ucommon::LinkedObject::Next
LinkedObject * Next
Definition: linked.h:62
ucommon::memalloc::~memalloc
virtual ~memalloc()
Definition: memory.cpp:119
ucommon::ObjectPager::get
void * get(unsigned item) const
Definition: memory.cpp:338
ucommon::ObjectPager::member::mem
void * mem
Definition: memory.h:268
ucommon::memalloc::purge
void purge(void)
Definition: memory.cpp:143
ucommon::PagerObject::release
void release(void) __OVERRIDE
Definition: memory.cpp:916
export.h
ucommon::PagerObject::dealloc
void dealloc(void) __OVERRIDE
Definition: memory.cpp:911
ucommon::PagerPool::mutex
pthread_mutex_t mutex
Definition: memory.h:828
ucommon::ObjectPager::member::set
void set(member *node)
Definition: memory.h:273
ucommon::PagerObject::pager
PagerPool * pager
Definition: memory.h:791
out
static shell::stringopt out('o', "--output", _TEXT("output file"), "filename", "-")
ucommon::ObjectPager::ObjectPager
ObjectPager(size_t objsize, size_t pagesize=256)
Definition: memory.cpp:312
ucommon
Definition: access.cpp:23
ucommon::memalloc::assign
void assign(memalloc &source)
Definition: memory.cpp:59
ucommon::LinkedObject::getNext
LinkedObject * getNext(void) const
Definition: linked.h:138
ucommon::mempager::assign
void assign(mempager &source)
Definition: memory.cpp:290
ucommon::ObjectPager::assign
void assign(ObjectPager &source)
Definition: memory.cpp:322
ucommon::memalloc::size
size_t size(void) const
Definition: memory.h:125
ucommon::ObjectPager::add
void * add(void)
Definition: memory.cpp:430
ucommon::ObjectPager::list
void ** list(void)
Definition: memory.cpp:447
ucommon::LinkedObject::enlist
void enlist(LinkedObject **root)
Definition: linked.cpp:62
ucommon::memalloc::align
size_t align
Definition: memory.h:66
ucommon::memalloc::page
page_t * page
Definition: memory.h:77
object.h
ucommon::StringPager::member::member
member(LinkedObject **root, const char *data)
Definition: memory.cpp:464
ucommon::String
Definition: string.h:78
result
static void result(const char *path, int code)
Definition: mdsum.cpp:35
ucommon::StringPager::get
const char * get(unsigned item) const
Definition: memory.cpp:620
ucommon::mempager::_alloc
virtual void * _alloc(size_t size) __OVERRIDE
Definition: memory.cpp:279
ucommon::memalloc::mempage::next
struct mempage * next
Definition: memory.h:70
__THROW_ALLOC
#define __THROW_ALLOC()
Definition: platform.h:52
ucommon::memalloc::mempage::used
unsigned used
Definition: memory.h:73
ucommon::DirPager::filter
virtual bool filter(char *filename, size_t size) __OVERRIDE
Definition: memory.cpp:835
ucommon::DirPager::assign
void assign(DirPager &source)
Definition: memory.cpp:821
ucommon::autorelease::operator+=
void operator+=(LinkedObject *object)
Definition: memory.cpp:893
ucommon::StringPager
Definition: memory.h:401
ucommon::StringPager::pop
const char * pop(void)
Definition: memory.cpp:687
ucommon::copy
T copy(const T &src)
Definition: generics.h:395
caddr_t
#define caddr_t
Definition: file.h:86
ucommon::ObjectPager
Definition: memory.h:262
ucommon::StringPager::member::set
void set(member *node)
Definition: memory.h:431
ucommon::ObjectPager::invalid
void * invalid(void) const
Definition: memory.cpp:425
ucommon::StringPager::join
String join(const char *prefix=NULL, const char *middle=NULL, const char *suffix=NULL)
Definition: memory.cpp:532
ucommon::StringPager::filter
virtual bool filter(char *text, size_t size)
Definition: memory.cpp:509
ucommon::dir::open
void open(const char *path)
Definition: fsys.cpp:909
ucommon::PagerObject
Definition: memory.h:783
ucommon::strdup_t
Definition: string.h:1750
ucommon::memalloc::page_t
struct ucommon::memalloc::mempage page_t
__THROW_RUNTIME
#define __THROW_RUNTIME(x)
Definition: platform.h:51
ucommon::PagerObject::PagerObject
PagerObject()
Definition: memory.cpp:900
ucommon::ncompare
static int ncompare(const void *o1, const void *o2)
Definition: linked.cpp:264
ucommon::StringPager::StringPager
StringPager(size_t pagesize=256)
Definition: memory.cpp:476
ucommon::CountedObject::reset
void reset(void)
Definition: object.h:85
ucommon::mempager::_lock
virtual void _lock(void) __OVERRIDE
Definition: memory.cpp:248
quote
static shell::stringopt quote('q', "--quote", _TEXT("set quote for each argument"), "string", "")
ucommon::autorelease::release
void release(void)
Definition: memory.cpp:882
ucommon::memalloc::pagesize
size_t pagesize
Definition: memory.h:66
ucommon::ObjectPager::members
unsigned members
Definition: memory.h:291
ucommon::StringPager::member::text
const char * text
Definition: memory.h:426
ucommon::mempager::_unlock
virtual void _unlock(void) __OVERRIDE
Definition: memory.cpp:253
ucommon::String::INSENSITIVE
Definition: string.h:95
ucommon::mempager::mutex
pthread_mutex_t mutex
Definition: memory.h:187
ucommon::memalloc::pager
page_t * pager(void)
Definition: memory.cpp:161
ucommon::LinkedObject::release
virtual void release(void) __OVERRIDE
Definition: linked.cpp:210
thread.h
ucommon::autorelease::~autorelease
~autorelease()
Definition: memory.cpp:877
ucommon::StringPager::member
Definition: memory.h:423
ucommon::ObjectPager::pull
void * pull(void)
Definition: memory.cpp:360
ucommon::mempager::~mempager
virtual ~mempager()
Definition: memory.cpp:242
ucommon::StringPager::clear
void clear(void)
Definition: memory.cpp:635
ucommon::memalloc::_alloc
virtual void * _alloc(size_t size) __OVERRIDE
Definition: memory.cpp:202
ucommon::pager
Definition: memory.h:853
ucommon::String::token
static char * token(char *text, char **last, const char *list, const char *quote=NULL, const char *end=NULL)
Definition: string.cpp:1305
ucommon::dir::close
void close(void)
Definition: fsys.cpp:808
ucommon::DirPager::DirPager
DirPager()
Definition: memory.cpp:815
ucommon::memalloc::utilization
unsigned utilization(void) const
Definition: memory.cpp:124
__THROW_SIZE
#define __THROW_SIZE(x)
Definition: platform.h:49
ucommon::ObjectPager::last
member * last
Definition: memory.h:294
ucommon::dup
T * dup(const T &object)
Definition: generics.h:324
ucommon::StringPager::split
unsigned split(const char *text, const char *string, unsigned flags=0)
Definition: memory.cpp:555
ucommon::linked_pointer
Definition: linked.h:991
ucommon::PagerPool::freelist
LinkedObject * freelist
Definition: memory.h:827
ucommon::PagerPool::PagerPool
PagerPool()
Definition: memory.cpp:926
ucommon::PagerObject::retain
void retain(void) __OVERRIDE
Definition: memory.cpp:921
ucommon::StringPager::count
unsigned count(void) const
Definition: memory.h:459
ucommon::ObjectPager::clear
void clear(void)
Definition: memory.cpp:351
ucommon::CountedObject::retain
void retain(void) __OVERRIDE
Definition: object.cpp:43
ucommon::StringPager::last
member * last
Definition: memory.h:635
ucommon::mempager::mempager
mempager(size_t page=0)
Definition: memory.cpp:230
ucommon::PagerPool::~PagerPool
virtual ~PagerPool()
Definition: memory.cpp:932
fsys.h
ucommon::StringPager::set
void set(unsigned item, const char *string)
Definition: memory.cpp:601
ucommon::ObjectPager::root
LinkedObject * root
Definition: memory.h:292
ucommon::LinkedObject
Definition: linked.h:55
ucommon::ObjectPager::pop
void * pop(void)
Definition: memory.cpp:395
ucommon::dir
Definition: fsys.h:743
ucommon::str
String str(Socket &so, size_t size)
Definition: socket.cpp:3507
nullptr
const class nullptr_t nullptr
ucommon::linked_pointer::next
void next(void)
Definition: linked.h:1106
ucommon::PagerObject::reset
void reset(void)
Definition: memory.cpp:905
ucommon::fsys::is_dir
static bool is_dir(const char *path)
Definition: fsys.cpp:1500
ucommon::DirPager
Definition: memory.h:653
buffer
static uint8_t buffer[65536]
Definition: zerofill.cpp:27
ucommon::ObjectPager::typesize
size_t typesize
Definition: memory.h:293
__THROW_RANGE
#define __THROW_RANGE(x)
Definition: platform.h:50
ucommon::StringPager::push
void push(const char *text)
Definition: memory.cpp:664
ucommon::memalloc
Definition: memory.h:61
ucommon::ObjectPager::member::member
member()
Definition: memory.cpp:306
ucommon::StringPager::list
char ** list(void)
Definition: memory.cpp:799
ucommon::mempager::dealloc
virtual void dealloc(void *memory)
Definition: memory.cpp:275
ucommon::StringPager::assign
void assign(StringPager &source)
Definition: memory.cpp:485
ucommon::dir::read
ssize_t read(char *buffer, size_t count)
Definition: fsys.cpp:736
ucommon::String::collate
static int collate(const char *text1, const char *text2)
Definition: string.h:1099
string.h
ucommon::autorelease::pool
LinkedObject * pool
Definition: memory.h:744
prefix
static char prefix[80]
Definition: args.cpp:33
ucommon::StringPager::index
char ** index
Definition: memory.h:636
ucommon::StringPager::token
unsigned token(const char *text, const char *list, const char *quote=NULL, const char *end=NULL)
Definition: memory.cpp:515
ucommon::PagerPool::get
PagerObject * get(size_t size)
Definition: memory.cpp:946
ucommon::StringPager::root
LinkedObject * root
Definition: memory.h:405
ucommon::ObjectPager::member
Definition: memory.h:265
ucommon::DirPager::dir
const char * dir
Definition: memory.h:659
ucommon::StringPager::size
size_t size(void) const
Definition: memory.h:626
ucommon::DirPager::load
bool load(const char *path)
Definition: memory.cpp:849
ucommon::ObjectPager::index
void ** index
Definition: memory.h:295
ucommon::memalloc::memalloc
memalloc(size_t page=0)
Definition: memory.cpp:71
ucommon::memalloc::count
unsigned count
Definition: memory.h:67
ucommon::String::dup
static char * dup(const char *text)
Definition: string.cpp:1390
ucommon::CountedObject::release
void release(void) __OVERRIDE
Definition: object.cpp:48
ucommon::StringPager::members
unsigned members
Definition: memory.h:404
ucommon::addr
const struct sockaddr * addr(Socket::address &address)
Definition: socket.h:2089
suffix
static char suffix[80]
Definition: args.cpp:34
ucommon::ObjectPager::push
void * push(void)
Definition: memory.cpp:378
memory.h
ucommon::mempager::purge
void purge(void)
Definition: memory.cpp:268
ucommon::mempager::utilization
unsigned utilization(void)
Definition: memory.cpp:258
ucommon::autorelease::autorelease
autorelease()
Definition: memory.cpp:872
ucommon::StringPager::pull
const char * pull(void)
Definition: memory.cpp:644
ucommon::StringPager::add
void add(const char *text)
Definition: memory.cpp:719
ucommon::memalloc::limit
unsigned limit
Definition: memory.h:80
ucommon::is
bool is(T &object)
Definition: generics.h:292
ucommon::StringPager::sort
void sort(void)
Definition: memory.cpp:775
ucommon::CountedObject
Definition: object.h:56