1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
/***********************************************************************
Memory primitives
(c) 1994, 1995 Innobase Oy
Created 5/30/1994 Heikki Tuuri
************************************************************************/
#ifndef ut0mem_h
#define ut0mem_h
#include "univ.i"
#include <string.h>
#include <stdlib.h>
/* The total amount of memory currently allocated from the OS with malloc */
extern ulint ut_total_allocated_memory;
UNIV_INLINE
void*
ut_memcpy(void* dest, void* sour, ulint n);
UNIV_INLINE
void*
ut_memmove(void* dest, void* sour, ulint n);
UNIV_INLINE
int
ut_memcmp(void* str1, void* str2, ulint n);
/**************************************************************************
Allocates memory. Sets it also to zero if UNIV_SET_MEM_TO_ZERO is
defined and set_to_zero is TRUE. */
void*
ut_malloc_low(
/*==========*/
/* out, own: allocated memory */
ulint n, /* in: number of bytes to allocate */
ibool set_to_zero); /* in: TRUE if allocated memory should be set
to zero if UNIV_SET_MEM_TO_ZERO is defined */
/**************************************************************************
Allocates memory. Sets it also to zero if UNIV_SET_MEM_TO_ZERO is
defined. */
void*
ut_malloc(
/*======*/
/* out, own: allocated memory */
ulint n); /* in: number of bytes to allocate */
/**************************************************************************
Tests if malloc of n bytes would succeed. ut_malloc() asserts if memory runs
out. It cannot be used if we want to return an error message. Prints to
stderr a message if fails. */
ibool
ut_test_malloc(
/*===========*/
/* out: TRUE if succeeded */
ulint n); /* in: try to allocate this many bytes */
/**************************************************************************
Frees a memory bloock allocated with ut_malloc. */
void
ut_free(
/*====*/
void* ptr); /* in, own: memory block */
/**************************************************************************
Frees in shutdown all allocated memory not freed yet. */
void
ut_free_all_mem(void);
/*=================*/
UNIV_INLINE
char*
ut_strcpy(char* dest, char* sour);
UNIV_INLINE
ulint
ut_strlen(const char* str);
UNIV_INLINE
int
ut_strcmp(void* str1, void* str2);
/**************************************************************************
Catenates two strings into newly allocated memory. The memory must be freed
using mem_free. */
char*
ut_str_catenate(
/*============*/
/* out, own: catenated null-terminated string */
char* str1, /* in: null-terminated string */
char* str2); /* in: null-terminated string */
/**************************************************************************
Return a copy of the given string. The returned string must be freed
using mem_free. */
char*
ut_strdup(
/*======*/
/* out, own: cnull-terminated string */
char* str); /* in: null-terminated string */
/**************************************************************************
Checks if a null-terminated string contains a certain character. */
ibool
ut_str_contains(
/*============*/
char* str, /* in: null-terminated string */
char c); /* in: character */
#ifndef UNIV_NONINL
#include "ut0mem.ic"
#endif
#endif
|