mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 12:02:42 +01:00
2b9a8afa50
BitKeeper/etc/logging_ok: auto-union Build-tools/mysql-copyright-2: Auto merged include/violite.h: Auto merged innobase/btr/btr0btr.c: Auto merged innobase/buf/buf0buf.c: Auto merged innobase/buf/buf0flu.c: Auto merged innobase/buf/buf0lru.c: Auto merged innobase/dict/dict0dict.c: Auto merged innobase/dict/dict0mem.c: Auto merged innobase/fsp/fsp0fsp.c: Auto merged innobase/fut/fut0lst.c: Auto merged innobase/ha/hash0hash.c: Auto merged innobase/include/buf0buf.ic: Auto merged innobase/include/buf0lru.h: Auto merged innobase/include/data0data.h: Auto merged innobase/include/dict0dict.h: Auto merged innobase/include/dict0mem.h: Auto merged innobase/include/fsp0fsp.h: Auto merged innobase/include/hash0hash.h: Auto merged innobase/include/lock0lock.h: Auto merged innobase/include/log0log.h: Auto merged innobase/include/log0log.ic: Auto merged innobase/include/mem0dbg.ic: Auto merged innobase/include/mem0pool.h: Auto merged innobase/include/mtr0mtr.h: Auto merged innobase/include/sync0rw.h: Auto merged innobase/include/sync0sync.h: Auto merged innobase/include/trx0roll.h: Auto merged innobase/include/trx0trx.h: Auto merged innobase/include/ut0mem.h: Auto merged innobase/lock/lock0lock.c: Auto merged innobase/log/log0log.c: Auto merged innobase/mem/mem0dbg.c: Auto merged innobase/mem/mem0pool.c: Auto merged innobase/mtr/mtr0mtr.c: Auto merged innobase/pars/lexyy.c: Auto merged innobase/pars/pars0opt.c: Auto merged innobase/que/que0que.c: Auto merged innobase/rem/rem0cmp.c: Auto merged innobase/row/row0ins.c: Auto merged innobase/row/row0mysql.c: Auto merged innobase/row/row0upd.c: Auto merged innobase/srv/srv0srv.c: Auto merged innobase/srv/srv0start.c: Auto merged innobase/sync/sync0rw.c: Auto merged innobase/sync/sync0sync.c: Auto merged innobase/thr/thr0loc.c: Auto merged innobase/trx/trx0purge.c: Auto merged innobase/trx/trx0roll.c: Auto merged innobase/trx/trx0sys.c: Auto merged innobase/trx/trx0trx.c: Auto merged innobase/usr/usr0sess.c: Auto merged innobase/ut/ut0mem.c: Auto merged mysql-test/r/func_if.result: Auto merged mysql-test/r/type_date.result: Auto merged mysql-test/t/type_date.test: Auto merged mysql-test/t/type_decimal.test: Auto merged mysys/mf_tempfile.c: Auto merged netware/BUILD/nwbootstrap: Auto merged netware/Makefile.am: Auto merged scripts/mysqld_safe.sh: Auto merged sql/item_cmpfunc.cc: Auto merged mysql-test/t/func_if.test: Auto merged sql/mysqld.cc: Auto merged sql/opt_range.cc: Auto merged sql/sql_acl.cc: Auto merged sql/sql_parse.cc: Auto merged support-files/my-innodb-heavy-4G.cnf.sh: Auto merged Build-tools/Do-compile: Merge with 4.0 Build-tools/mysql-copyright: Merge with 4.0 client/mysqltest.c: Merge with 4.0 include/my_global.h: Merge with 4.0 innobase/buf/buf0rea.c: Merge with 4.0 innobase/data/data0type.c: Merge with 4.0 innobase/ibuf/ibuf0ibuf.c: Merge with 4.0 innobase/include/buf0buf.h: Merge with 4.0 innobase/include/data0type.h: Merge with 4.0 innobase/include/mem0mem.h: Merge with 4.0 innobase/include/mem0mem.ic: Merge with 4.0 innobase/log/log0recv.c: Merge with 4.0 libmysql/libmysql.c: Merge with 4.0 libmysqld/Makefile.am: Merge with 4.0 mysql-test/r/range.result: Merge with 4.0 mysql-test/r/type_decimal.result: Merge with 4.0 mysql-test/t/range.test: Merge with 4.0 netware/BUILD/mwenv: Merge with 4.0 netware/mysql_test_run.c: Merge with 4.0 scripts/mysql_install_db.sh: Merge with 4.0 sql/field.cc: Merge with 4.0 sql/field.h: Merge with 4.0 sql/item_cmpfunc.h: Merge with 4.0 support-files/my-huge.cnf.sh: Merge with 4.0 support-files/my-large.cnf.sh: Merge with 4.0 support-files/my-medium.cnf.sh: Merge with 4.0 support-files/my-small.cnf.sh: Merge with 4.0 support-files/mysql.spec.sh: Merge with 4.0
156 lines
4.7 KiB
C
156 lines
4.7 KiB
C
/***********************************************************************
|
||
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, const void* sour, ulint n);
|
||
|
||
UNIV_INLINE
|
||
void*
|
||
ut_memmove(void* dest, const void* sour, ulint n);
|
||
|
||
UNIV_INLINE
|
||
int
|
||
ut_memcmp(const void* str1, const 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 */
|
||
/**************************************************************************
|
||
Implements realloc. This is needed by /pars/lexyy.c. 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<65>
|
||
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. */
|
||
|
||
void*
|
||
ut_realloc(
|
||
/*=======*/
|
||
/* out, own: pointer to new mem block or NULL */
|
||
void* ptr, /* in: pointer to old block or NULL */
|
||
ulint size); /* in: desired size */
|
||
/**************************************************************************
|
||
Frees in shutdown all allocated memory not freed yet. */
|
||
|
||
void
|
||
ut_free_all_mem(void);
|
||
/*=================*/
|
||
|
||
UNIV_INLINE
|
||
char*
|
||
ut_strcpy(char* dest, const char* sour);
|
||
|
||
UNIV_INLINE
|
||
ulint
|
||
ut_strlen(const char* str);
|
||
|
||
UNIV_INLINE
|
||
int
|
||
ut_strcmp(const void* str1, const void* str2);
|
||
|
||
/**************************************************************************
|
||
Determine the length of a string when it is quoted with ut_strcpyq(). */
|
||
UNIV_INLINE
|
||
ulint
|
||
ut_strlenq(
|
||
/*=======*/
|
||
/* out: length of the string when quoted */
|
||
const char* str, /* in: null-terminated string */
|
||
char q); /* in: the quote character */
|
||
|
||
/**************************************************************************
|
||
Make a quoted copy of a string. */
|
||
|
||
char*
|
||
ut_strcpyq(
|
||
/*=======*/
|
||
/* out: pointer to end of dest */
|
||
char* dest, /* in: output buffer */
|
||
char q, /* in: the quote character */
|
||
const char* src); /* in: null-terminated string */
|
||
|
||
/**************************************************************************
|
||
Make a quoted copy of a fixed-length string. */
|
||
|
||
char*
|
||
ut_memcpyq(
|
||
/*=======*/
|
||
/* out: pointer to end of dest */
|
||
char* dest, /* in: output buffer */
|
||
char q, /* in: the quote character */
|
||
const char* src, /* in: string to be quoted */
|
||
ulint len); /* in: length of src */
|
||
|
||
#ifndef UNIV_NONINL
|
||
#include "ut0mem.ic"
|
||
#endif
|
||
|
||
#endif
|