MySQL是一種廣泛使用的關系型數據庫管理系統,被許多大型網站和應用程序使用。但是,你可能好奇MySQL是用哪種語言進行編寫的?
事實上,MySQL的底層是用C語言進行編寫的。C語言因其高效性和跨平臺性而備受青睞,因此被用于許多操作系統內核、應用程序和數據庫的開發。
/*
* mysql-common/dundle/my_malloc.c
*
* Copyright (c) 2000-2021, Oracle and/or its affiliates.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
...
void *my_malloc(size_t size, myf MyFlags ATTRIBUTE_UNUSED)
{
void *ptr;
DBUG_ENTER("my_malloc");
if (UNLIKELY(!size))
{
DBUG_PRINT("error", ("required size is zero"));
ptr = NULL;
}
else
{
ptr = malloc(size);
if (UNLIKELY(!ptr))
my_error_reporter(MYF(ME_OUT_OF_MEMORY),
"malloc(%lu) failed", (ulong) size);
else
mem_root_statistic(ptr, size);
}
DBUG_RETURN(ptr);
}
...
在這里,你可以看到MySQL的一個代碼片段,其中包括用C語言編寫的my_malloc函數。