• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: [OT] What kind of data is is returned by 'new' ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [OT] What kind of data is is returned by 'new' ?


  • Subject: Re: [OT] What kind of data is is returned by 'new' ?
  • From: Dirk Stegemann <email@hidden>
  • Date: Sat, 9 Jul 2005 02:26:23 +0300

Hello Mark & AgentM,

Am 07.07.2005 um 00:11 schrieb Mark Bessey:


all pages allocated to your process are zero-filled by the OS when they're first mapped in. You can't really depend on this in any useful way though - see below.


When I allocate a buffer using

    char* buffer = new char [numberOfBytes];

then the buffer seems to contain random data.


This is because this memory has previously been allocated to and written on by your process. The heap that "new" allocates out of is re-used as you allocate and free memory.



Thank you for this information.

Now I set up a test project (Xcode 2.1 carbon application) and put several calls to 'new' into the main.c file; I recognised that only calls to 'new' which were issued before calling any other (system) function returned a zero'd buffer. Afterwards, I always saw a couple of bytes containing non-zero values.

Actually, this is great because I thought of using such buffers as seed to a random function. So, I'm wondering if it's posssible for someone hassling around with my app to circumvent this randomising mechanism by somehow telling the system to *always* make 'new' return zero'd buffers... e.g., in DEBUG mode compiled applications will get allocated memory filled with 0xCC values (on Win32 systems).

Anyway, so far this seems to work fine :-)


Regards, Dirk Stegemann


_______________________________________________ Do not post admin requests to the list. They will be ignored. Xcode-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: [OT] What kind of data is is returned by 'new' ?
      • From: Bill Bumgarner <email@hidden>
    • Re: [OT] What kind of data is is returned by 'new' ?
      • From: Clark Cox <email@hidden>
References: 
 >[OT] What kind of data is is returned by 'new' ? (From: Dirk Stegemann <email@hidden>)
 >Re: [OT] What kind of data is is returned by 'new' ? (From: Mark Bessey <email@hidden>)

  • Prev by Date: Re: Adding existing jar file to XCode Swing Application
  • Next by Date: Traceback table question
  • Previous by thread: Re: [OT] What kind of data is is returned by 'new' ?
  • Next by thread: Re: [OT] What kind of data is is returned by 'new' ?
  • Index(es):
    • Date
    • Thread