内存分配问题?

发布于 2024-11-07 03:52:15 字数 481 浏览 0 评论 0原文

我正在unix服务器中执行Proc代码,proc将从文件中读取记录并将数据存储在结构数组中,经过一些处理后它将产生输出。当我从文件中读取 368700 条记录并在代码中进行处理时,意味着它执行良好。但是当我尝试从文件和进程中读取 370000 条记录时,我收到一条错误消息 ORA-12533: TNS:illegal ADDRESS 参数和非法地址。此错误的原因和可能的解决方案可能是什么?

我已经完成了如下的内存分配:

 int unsigned long  size=(atoi(argv[2]))+1;
 printf("\nthe size is %lu",size);
 printf("\n am here 1");
 what_if_var =(what_if*)malloc((size)*sizeof(what_if));
 temp_var    =(what_if*)malloc((size)*sizeof(what_if));

I am executing Proc code in unix server, the proc will read the record from file and store the data in array of structure and after some processing it will produce the output. When i read 368700 records from the file and process in the code means its executing fine. but when i try to read 370000 records from the file and process means, I am getting an error saying ORA-12533: TNS:illegal ADDRESS parameters and illegal address. What could be the cause and possible solution for this error?

I've done memory allocation like below:

 int unsigned long  size=(atoi(argv[2]))+1;
 printf("\nthe size is %lu",size);
 printf("\n am here 1");
 what_if_var =(what_if*)malloc((size)*sizeof(what_if));
 temp_var    =(what_if*)malloc((size)*sizeof(what_if));

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

何以畏孤独 2024-11-14 03:52:15
  1. 不要转换 malloc() 的返回值C 语言中的
  2. 最好在 malloc() 调用中写入 sizeof *what_if_var,以防 what_if_var 的类型实际上不是 what_if
  3. 请务必检查您是否没有返回 NULL 指针,以防内存分配失败。
  4. 调查一个进程可以使用的 RAM 量是否存在限制,一些系统管理员在共享计算机上执行此操作。
  5. 使用 size_t 来保存大小,它是 malloc() 参数的类型,因此它是有意义的。
  1. Don't cast the return value of malloc() in C.
  2. It's better to write sizeof *what_if_var in the call to malloc(), in case the type of what_if_var isn't really what_if.
  3. Always check that you didn't get a NULL pointer back, in case of low memory allocations can fail.
  4. Investigate if there perhaps is a limit to how much RAM a process can use, some sysadmins do this on shared machines.
  5. Use size_t to hold sizes, it's the type of malloc()'s argument so it makes sense.
绅刃 2024-11-14 03:52:15

您应该检查 malloc 是否返回 NULL,这意味着没有可用内存可供分配。您应该使用函数 free() 释放不再使用的数据的内存。

内存限制取决于操作系统及其配置。 32 位进程的内存限制可能是 2 GB 或 4 GB。

You should check if malloc returned NULL, it means that there is not available memory to be allocated. You should free the memory with data that you will not use again with the function free().

The memory limit depends of the operating system and its configuration. The limit of memory of a 32-bit process may be 2 GB or 4 GB.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文