Pelles C forum

C language => Windows questions => Topic started by: bitcoin on December 09, 2022, 10:56:13 PM

Title: malloc and 64 bit ?
Post by: bitcoin on December 09, 2022, 10:56:13 PM
Hello
If i use malloc in 64 bit program, this allocates memory in address,start in FFFFF...
and program don't work.
why?
Title: Re: malloc and 64 bit ?
Post by: John Z on December 10, 2022, 11:49:46 AM
Hi bitcoin,

Well I searched and searched but couldn't find the error code for "doesn't work"  :)
Seriously though you are not giving enough information to allow any help to be useful.

It seems you received no error message when using the malloc, but are saying something else
did not work and you seem to be suspecting/pointing to the memory address.  Other than
that what didn't work is unspecified.  You mention 64 bit specifically, have you tried 32 bit and
does it work as you wanted?

Can you zip and post a small project that demonstrates what doesn't work?

John Z

Title: Re: malloc and 64 bit ?
Post by: bitcoin on December 10, 2022, 03:08:34 PM
Hello, John Z
See attach
Title: Re: malloc and 64 bit ?
Post by: John Z on December 10, 2022, 05:21:46 PM
Thanks bitcoin,

Well other than two missing h files I don't see, or get, any error.  I ran both the std exe and the debug exe, no error.
Attached is the debug 'Local' tab, and a memory view of the x pointer.  BTW I set changed memset to 1 so it
is easy to see the memset results in memory.  The x location was also shown in debug by mouse hover over x
also attached screen shot and it matches the local display. The memory at the location was filled with 1s.

I'm at a loss to see a problem.

John Z

Title: Re: malloc and 64 bit ?
Post by: TimoVJL on December 10, 2022, 06:47:16 PM
In windows 7 x64 i got address 0000000000610068h
Title: Re: malloc and 64 bit ?
Post by: MrBcx on December 10, 2022, 07:19:24 PM
This works for me, 32-bit and 64-bit, Windows 10 Pro:

Code: [Select]
#include <stdio.h>     
#include <stdlib.h>     
#include <string.h>   

int main(void)
{
char *x = (char*)malloc(128);
memset(x,0,128);
return 0;
}
Title: Re: malloc and 64 bit ?
Post by: bitcoin on December 10, 2022, 08:48:16 PM
It is very strange. Because I have a problem. Okay, sorry, this is probably a local error.
I use Windows 10, no antivirus.

---
If you run my exe file from attach, it works?
Title: Re: malloc and 64 bit ?
Post by: John Z on December 10, 2022, 10:29:14 PM
Hi,

Yes as far as I can tell the original 1.exe from your zip runs just fine, no error report.
Attached is 1_me.exe from my compile. You can try it.
Attached is also a comparison of file size, mine is exactly  1K (1024) bytes larger.



John Z
Title: Re: malloc and 64 bit ?
Post by: bitcoin on December 11, 2022, 02:35:14 PM
Your exe works fine
my - crashes with error
ok, thanks, maybe I need to re-install PellesC Ide
Title: Re: malloc and 64 bit ?
Post by: John Z on December 11, 2022, 03:57:52 PM
Definitely something strange because your exe does not show any error on my system. maybe something corrupted on your system but might not necessarily be Pelles C.  Still worth a try to re-install to get 'fresh' .lib files.

I'm on Windows 11 home edition 21H2 build 22000.1219 btw.  I have windows 7 and windows 10  as well and I'm going to try your exe there too.


John Z

P.S. "No antivirus", but you are running Microsoft Defender and firewall I hope....
Title: Re: malloc and 64 bit ?
Post by: bitcoin on December 11, 2022, 03:59:51 PM
Yes, I use windef.
I will try Ida Free and BinDiff to find error. Because this is very strange.
Title: Re: malloc and 64 bit ?
Post by: bitcoin on December 11, 2022, 04:11:17 PM
I reinstalled and everything worked!
maybe delete this stupid topic?
Title: Re: malloc and 64 bit ?
Post by: John Z on December 11, 2022, 04:42:03 PM
Great news!  Never know though this might help someone else might -

John Z