简体   繁体   English

32位CPU处理器中的内存泄漏,而64位处理器CPU中无泄漏

[英]Memory leak in 32 bit CPU processor and no leak in 64 bit processor CPU

I have a C code that runs without any memory leak in 64 bit CPU processor but shows leak in 32 bit processor. 我有一个C代码,在64位CPU处理器中运行时没有任何内存泄漏,但在32位处理器中却显示泄漏。 What can be the reason for it. 可能是什么原因。 GCC 4.1.2 is the compiler and Debian is the operating system. GCC 4.1.2是编译器,Debian是操作系统。

That sounds weird. 这听起来很奇怪。 But it's too vague to answer, for me. 但这对我来说太模糊了。 Since you're on Linux though, I would recommend that you simply run the 32-bit version under Valgrind , with maximum memory tracking. 由于您使用的是Linux,因此我建议您仅在Valgrind下运行32位版本,并最大程度地跟踪内存。

Keep in mind that even though your own code is the same, you are still running two distinct programs -- there are different runtime libraries they are linked against. 请记住,即使您自己的代码相同,您仍在运行两个不同的程序-它们链接到不同的运行时库。 It could be that some aspect of your code is triggering a leak in one runtime and not another. 可能是代码的某些方面在一个运行时而不是另一个运行时触发了泄漏。 If that is the case, it can occur in one of two ways: 如果真是这样,它可能会以两种方式之一发生:

a) You've done nothing badly. a)你做得不好。 The problem is in the 32-bit runtime. 问题出在32位运行时中。

or 要么

b) You have something wrong, but something defensive in the 64-bit runtime is masking it. b)您有问题,但是在64位运行时中有防御措施正在掩盖它。

Really hard to tell without the code. 没有代码真的很难说。 Things that can go wrong 可能出错的事情

  • implicit conversions. 隐式转换。 in most places narrow data types are converted to signed or unsigned . 在大多数地方,窄数据类型会转换为有signedunsigned If you have implicit assumptions on the width of of these, you may have all kind of things: overflow, undefined behavior, compiler specific behavior 如果您对它们的宽度有隐式假设,则可能有各种各样的事情:溢出,未定义行为,编译器特定行为
  • missing function prototypes. 缺少功能原型。 oldish C assumes that a function that it doesn't know return an int . oldish C假定它不知道的函数返回一个int If in reality it returns a pointer (eg) you are in trouble. 如果实际上它返回一个指针(例如),则您有麻烦。
  • pointer to int conversions (or the other way round) 指向int转换的指针(或反之)

Your compiler is quite old. 您的编译器很旧。 You probably should try do obtain something more recent, if possible, or try something different like clang . 如果可能的话,您可能应该尝试获取较新的内容,或者尝试使用类似clang

Compile with all warnings on -Wall -Wextra ... and work on your code until it doesn't have any warning at all. 编译-Wall -Wextra ...上的所有警告,并处理您的代码,直到完全没有任何警告为止。

If your problem persists run it with valgrind as @unwind suggested. 如果问题仍然存在,请使用valgrind运行,如@unwind建议。

Then with a concrete problem some back here, so we might help you. 然后有一个具体的问题,请回到这里,以便我们为您提供帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM