Article View: comp.os.os2.programmer
Article #3439Re: malloc() and swapper.dat problems ....
From: Alex Stewart
Date: Mon, 11 Jan 1993 09:09
Date: Mon, 11 Jan 1993 09:09
39 lines
1713 bytes
1713 bytes
Takis Skagos (skagos@mercury.cs.uregina.ca) wrote:
: ---source code---
:
: #include <stdio.h>
:
: main()
: {
: int k = 0;
: int *p;
^^^ <-- (depends on the compiler, but at _least_ two bytes (I suspect 4 in
this case))
: setbuf(stdout,NULL); setbuf(stdin,NULL);
: p = (int *) malloc(12000000); /* bytes */
: printf("\n malloced 12000000 bytes.");
: while(k < 10000000 )
^^^^^^^^ <-- (10000000*4 bytes = 40000000 > 12000000)
: {
: p[k] = 1;
: k++;
: if(k % 10000 == 0)
: putchar('.');
: }
: free(p);
: printf("\n freed 12000000 bytes.\n");
: }
Counting your dots, it looks like it got to about k=3000000. Multiply that by
4 (the size of an int), and you get 12000000, or exactly the size of your
malloc. Try making p into a char*.
-alex
--
-----------------------------------------------------------------------------
Alex Stewart: Sysop of YBBS (510) 689-8952 | This space for rent.
stewarta@netcom.com .----------------------------'-------------------------
stewarta@carleton.edu | Somebody, somewhere, is offended by what I am saying.
-----------------------------------------------------------------------------
Technical Details
Message-ID:
<1993Jan11.090948.16559@netcom.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!wupost!csus.edu!netcom.com!stewartaReferences:
<1993Jan10.200412.454149@sue.cc.uregina.ca>Show Full Headers
Complete Article Headers
Newsgroups: comp.os.os2.programmer Path: arc1-ca.pugleaf.net!sparky!uunet!wupost!csus.edu!netcom.com!stewarta From: stewarta@netcom.com (Alex Stewart) Subject: Re: malloc() and swapper.dat problems .... Message-ID: <1993Jan11.090948.16559@netcom.com> Organization: Netcom - Online Communication Services (408 241-9760 guest) X-Newsreader: Tin 1.1 PL5 References: <1993Jan10.200412.454149@sue.cc.uregina.ca> Date: Mon, 11 Jan 1993 09:09:48 GMT Lines: 39