MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ut0mem.cc File Reference
#include "ut0mem.h"
#include "os0thread.h"
#include "srv0srv.h"
#include <stdlib.h>
Include dependency graph for ut0mem.cc:

Go to the source code of this file.

Classes

struct  ut_mem_block_t

Macros

#define UT_MEM_MAGIC_N   1601650166

Functions

UNIV_INTERN void ut_mem_init (void)
UNIV_INTERN void * ut_malloc_low (ulint n, ibool assert_on_error)
UNIV_INTERN void ut_free (void *ptr)
UNIV_INTERN void * ut_realloc (void *ptr, ulint size)
UNIV_INTERN void ut_free_all_mem (void)
UNIV_INTERN ulint ut_strlcpy (char *dst, const char *src, ulint size)
UNIV_INTERN ulint ut_strlcpy_rev (char *dst, const char *src, ulint size)
UNIV_INTERN ulint ut_strcount (const char *s1, const char *s2)
char * ut_str3cat (const char *s1, const char *s2, const char *s3)
UNIV_INTERN char * ut_strreplace (const char *str, const char *s1, const char *s2)

Variables

UNIV_INTERN ulint ut_total_allocated_memory = 0
UNIV_INTERN os_fast_mutex_t ut_list_mutex

Detailed Description

Memory primitives

Created 5/11/1994 Heikki Tuuri

Definition in file ut0mem.cc.

Macro Definition Documentation

#define UT_MEM_MAGIC_N   1601650166
The value of ut_mem_block_t::magic_n.  Used in detecting

memory corruption.

Definition at line 61 of file ut0mem.cc.

Function Documentation

UNIV_INTERN void ut_free ( void *  ptr)

Frees a memory block allocated with ut_malloc. Freeing a NULL pointer is a nop.

Parameters
ptrin, own: memory block, can be NULL

Definition at line 213 of file ut0mem.cc.

Here is the caller graph for this function:

UNIV_INTERN void ut_free_all_mem ( void  )

Frees in shutdown all allocated memory not freed yet.

Definition at line 329 of file ut0mem.cc.

UNIV_INTERN void* ut_malloc_low ( ulint  n,
ibool  assert_on_error 
)

Allocates memory.

Returns
own: allocated memory
Parameters
nin: number of bytes to allocate
assert_on_errorin: if TRUE, we crash mysqld if the memory cannot be allocated

Definition at line 93 of file ut0mem.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INTERN void ut_mem_init ( void  )

Initializes the mem block list at database startup.

Definition at line 78 of file ut0mem.cc.

Here is the caller graph for this function:

UNIV_INTERN void* ut_realloc ( void *  ptr,
ulint  size 
)

Implements realloc. This is needed by /pars/lexyy.cc. Otherwise, you should not use this function because the allocation functions in mem0mem.h are the recommended ones in InnoDB.

man realloc in Linux, 2004:

   realloc()  changes the size of the memory block pointed to
   by ptr to size bytes.  The contents will be  unchanged  to
   the minimum of the old and new sizes; newly allocated mem-
   ory will be uninitialized.  If ptr is NULL,  the  call  is
   equivalent  to malloc(size); if size is equal to zero, the
   call is equivalent to free(ptr).  Unless ptr is  NULL,  it
   must  have  been  returned by an earlier call to malloc(),
   calloc() or realloc().

RETURN VALUE realloc() returns a pointer to the newly allocated memory, which is suitably aligned for any kind of variable and may be different from ptr, or NULL if the request fails. If size was equal to 0, either NULL or a pointer suitable to be passed to free() is returned. If realloc() fails the original block is left untouched - it is not freed or moved.

Returns
own: pointer to new mem block or NULL
Parameters
ptrin: pointer to old block or NULL
sizein: desired size

Definition at line 273 of file ut0mem.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INTERN ulint ut_strcount ( const char *  s1,
const char *  s2 
)

Return the number of times s2 occurs in s1. Overlapping instances of s2 are only counted once.

Returns
the number of times s2 occurs in s1
Parameters
s1in: string to search in
s2in: string to search for

Definition at line 415 of file ut0mem.cc.

Here is the caller graph for this function:

UNIV_INTERN ulint ut_strlcpy ( char *  dst,
const char *  src,
ulint  size 
)

Copies up to size - 1 characters from the NUL-terminated string src to dst, NUL-terminating the result. Returns strlen(src), so truncation occurred if the return value >= size.

Returns
strlen(src)
Parameters
dstin: destination buffer
srcin: source buffer
sizein: size of destination buffer

Definition at line 367 of file ut0mem.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INTERN ulint ut_strlcpy_rev ( char *  dst,
const char *  src,
ulint  size 
)

Like ut_strlcpy, but if src doesn't fit in dst completely, copies the last (size - 1) bytes of src, not the first.

Returns
strlen(src)
Parameters
dstin: destination buffer
srcin: source buffer
sizein: size of destination buffer

Definition at line 391 of file ut0mem.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

UNIV_INTERN char* ut_strreplace ( const char *  str,
const char *  s1,
const char *  s2 
)

Replace every occurrence of s1 in str with s2. Overlapping instances of s1 are only replaced once.

Returns
own: modified string, must be freed with mem_free()
Parameters
strin: string to operate on
s1in: string to replace
s2in: string to replace s1 with

Definition at line 476 of file ut0mem.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

UNIV_INTERN os_fast_mutex_t ut_list_mutex

Mutex protecting ut_total_allocated_memory and ut_mem_block_list

Definition at line 44 of file ut0mem.cc.

UNIV_INTERN ulint ut_total_allocated_memory = 0
The total amount of memory currently allocated from the operating

system with os_mem_alloc_large() or malloc(). Does not count malloc() if srv_use_sys_malloc is set. Protected by ut_list_mutex.

Definition at line 41 of file ut0mem.cc.