c++ - C/C++ 中 char *(字符指针)的大小会有所不同吗? - 用于数据库列固定大小

标签 c++ mysql c database pointers

根据下面的代码,我得到一个字符指针的大小是 8 个字节。然而这个site char 指针的大小为 1 个字节。

#include <stdio.h>



int main(void ){

char *a = "saher asd asd asldasdas;daksd ahwal";
printf(" nSize = %d \n", sizeof(a));

return 0;

}

总是这样吗?我正在为我正在实现的一个简单数据库编写一个连接器,并希望将 mysql 的 TEXT 字段读入我的数据库。由于 TEXT 具有可变大小,我想知道我的列类型/元数据是否可以具有 8 个字节的固定大小,我将指针存储在内存中的字符串 (char *) 中?

最佳答案

per the following code, I get the size of a character pointer is 8 bytes. Yet this site has a size of 1 byte for the char pointer.

它是实现定义的。在 64 位 Intel 系统上通常为 8 个,在 32 位 Intel 系统上通常为 4 个。不要依赖它的任何特定尺寸。

I am writing a connector for a simple database I am implementing and want to read TEXT field of mysql into my database. Since TEXT has variable size, I was wondering if my column can have a fixed size of 8 bytes where I store the pointer in memory to the string (char *)?

将指针存储到数据库的内存中毫无意义。数据库用于持久数据。另一方面,存储在内存中的数据很容易在进程退出(或系统重启)时消失。

关于c++ - C/C++ 中 char *(字符指针)的大小会有所不同吗? - 用于数据库列固定大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22056689/

相关文章:

c++ - 从 'const void*' 到 'PVOID {aka void*}' 的无效转换 [-fpermissive]

c++ - 如何释放 CvMat 指针 vector 的内存?

c++ - C++中声明指针指针的效率

mysql - 仅允许通过特定应用程序连接 DBMS 用户

mysql - SQL 计数多对多

c - 在C中逐行写入文件

c++ - 如何使用 Windows API 获取 "cryptographically strong"随机字节?

c++ - 代码运行时 OpenGL 白色窗口 glew/glfw3

c++ - C语言中有 'minimizing stack overflow of an array'之类的东西吗?

php - 我的 pdo 登录功能需要帮助