18 #include "mysys_priv.h"
19 #include "my_static.h"
20 #include "mysys_err.h"
36 void* my_once_alloc(
size_t Size, myf MyFlags)
38 size_t get_size, max_left;
43 Size= ALIGN_SIZE(Size);
44 prev= &my_once_root_block;
46 for (next=my_once_root_block ; next && next->left < Size ; next= next->next)
48 if (next->left > max_left)
54 get_size= Size+ALIGN_SIZE(
sizeof(
USED_MEM));
55 if (max_left*4 < my_once_extra && get_size < my_once_extra)
56 get_size=my_once_extra;
58 if ((next = (
USED_MEM*) malloc(get_size)) == 0)
61 if (MyFlags & (MY_FAE+MY_WME))
62 my_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_WAITTANG+ME_FATALERROR), get_size);
65 DBUG_PRINT(
"test",(
"my_once_malloc %lu byte malloced", (ulong) get_size));
68 next->left= get_size-ALIGN_SIZE(
sizeof(
USED_MEM));
71 point= (uchar*) ((
char*) next+ (next->size-next->left));
74 if (MyFlags & MY_ZEROFILL)
75 memset(point, 0, Size);
76 return((
void*) point);
80 char *my_once_strdup(
const char *src,myf myflags)
82 size_t len= strlen(src)+1;
83 uchar *dst= my_once_alloc(len, myflags);
85 memcpy(dst, src, len);
90 void *my_once_memdup(
const void *src,
size_t len, myf myflags)
92 uchar *dst= my_once_alloc(len, myflags);
94 memcpy(dst, src, len);
106 void my_once_free(
void)
109 DBUG_ENTER(
"my_once_free");
111 for (next=my_once_root_block ; next ; )
113 old=next; next= next->next ;
116 my_once_root_block=0;