Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7066753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:07:07+00:00 2026-05-28T05:07:07+00:00

I am working on a code that, among other things, must save a zero-filled

  • 0

I am working on a code that, among other things, must save a zero-filled file. It can expect to create a file from 10MB to even 1GB blank.

It must be similar to this Unix command:

dd if=/dev/zero of=my_image.dsk count=20480

I could do this one work with small sizes:

int totalSize = 1024*1024;
char buf[totalSize];
strcpy(buf,"");

NSData *theData = [NSData dataWithBytes:buf length:sizeof(buf)];

//NSLog(@"%@", theData);
NSLog(@"%lu", sizeof(buf));

[theData writeToFile:@"/Users/foo/Desktop/my_image.dsk" atomically:YES];

But if I try a bigger value (1024*1024*10, for instance), it crashes.
So I tried:

NSFileManager *ddd = [[NSFileManager alloc ] init];
[ddd createFileAtPath:@"/Users/foo/Desktop/my_image.dsk" contents:[NSData data] attributes:nil];

It creates an empty file, but is not good because the file size is zero. It should not be zero.

I spent hours trying to find an answer without success. I want to do this in Obj-C, but C is also an option before I go nuts.

Please, someone give-me some light!

Thanks in advance!

— Edit —

Thanks everyone, but one more thing: is it possible to write without allocating everything on memory?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:07:08+00:00Added an answer on May 28, 2026 at 5:07 am

    You can use dd. This will let you write, e.g., 10 GB without worrying about memory or address space.

    NSTask *task = [NSTask new];
    long size = ...; // Note! dd multiplies this by 512 by default
    NSString *path = ...;
    [task setLaunchPath:@"/bin/dd"];
    [task setArguments:[NSArray arrayWithObjects:@"dd", @"if=/dev/zero",
        [NSString stringWithFormat:@"of=%s", [path fileSystemRepresentation]],
        [NSString stringWithFormat:@"count=%ld", size],
        nil]];
    [task launch];
    [task waitUntilExit];
    if ([task terminationStatus] != 0) {
        // an error occurred...
    }
    [task release];
    

    An advantage is that sophisticated users can kill dd if something goes wrong.

    About sandboxing: My suspicion is that this will work fine even in a sandbox, but I’d be curious to know for sure. According to documentation (link), a subprocess “simply inherits the sandbox of the process that created it.” This is exactly how you’d expect it to work on Unix.

    You can be sure that dd will stick around since Apple claims that OS X conforms to SUSv3.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on some logging code that supposed to - among other things
I'm working on an app that (among other things) uses UIImagePicker to grab an
I'm working on an application which among other things downloads items that belong to
I'm working on an app that, among other things, uses the device's camera to
I'm building an application that among other things allows users to upload documents. I
Recently I have been working on a project where, among other things, we want
I am currently trying to make a bookmarklet that adds, among other things, a
I'm working on code that does nearest-neighbor queries. There are two simple ideas that
I'm working on code that's supposed to start the screensaver defined by the user
I've recently been working with code that looks like this: using namespace std; class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.