Thread: How to write files more faster in C

  1. #31
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Yeah right. How is integer = 1 byte?
    This code doesn't even compile. The array is TOO BIG.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #32
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by Elysia View Post

    No, it should return success or failure, just as I mentioned in the other post. A utility function should never explicitly terminate the program. That should be done by the main code. And there's a reason for that, too. To fix things, to recover, to clean up, etc.
    It's pointless doing anything other than terminating the program, I am not
    in the habit of writing pointless code. It's just.....well pointless.

  3. #33
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by Elysia View Post
    Yeah right. How is integer = 1 byte?
    This code doesn't even compile. The array is TOO BIG.
    Perhaps you should get a better compiler!!!

  4. #34
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by esbo View Post
    It's pointless doing anything other than terminating the program, I am not
    in the habit of writing pointless code. It's just.....well pointless.
    It's NOT pointless. The user might have specified an improper path or made a mistake in the input filename. In that you should notify the user and not terminate the application.

    Quote Originally Posted by esbo View Post
    Perhaps you should get a better compiler!!!
    Or you might start writing better code!
    Where the hell do you think that big array is placed?

    Even so, on Windows, you only have 2 GB of virtual memory and 4 GB > 2 GB!

    Try to compile with
    int pname[0x6FFFFFFF/4];
    That's 1 879 048 191 bytes of memory.
    When I run the program, the swap file skyrockets from 1.27 GB to 3.06 GB.
    So I guess it's placed in memory, after all! Just that it's too big to fit into physical memory at once!
    Last edited by Elysia; 01-07-2008 at 03:47 PM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #35
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by Elysia View Post
    It's NOT pointless. The user might have specified an improper path or made a mistake in the input filename. In that you should notify the user and not terminate the application.

    The path is hardcoded into th program.
    There is nohing that can be done other than terminate the program.

  6. #36
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It's still bad practice. When someone writes real program, they don't terminate the application that way.
    Are you intending that to be main or a utility function?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #37
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by Elysia View Post

    Even so, on Windows, you only have 2 GB of virtual memory and 4 GB > 2 GB!

    Try to compile with
    int pname[0x6FFFFFFF/4];
    That's 1 879 048 191 bytes of memory.
    When I run the program, the swap file skyrockets from 1.27 GB to 3.06 GB.
    So I guess it's placed in memory, after all! Just that it's too big to fit into physical memory at once!

    He didn't specify operating system.
    It's not my fault windows cannot cope with large memory demands.
    Blame Bill Gates for that, you think with all his money he could fix it.
    If you want to ensure the data is in one byte chunks then use char instead of int.
    It worked fine when I did that. It ran in a couple of minutes, no crashs no problems.
    I gig file created no problem!!
    On another system it would have greated a 4 gig file with no problems.

  8. #38
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by esbo View Post
    He didn't specify operating system.
    Irrelevant.

    It's not my fault windows cannot cope with large memory demands.
    No, it's your fault for using such a ridiculous amount of memory.

    Blame Bill Gates for that, you think with all his money he could fix it.
    The problem isn't as simple as you think it is. Do you even know WHY it's limited?

    If you want to ensure the data is in one byte chunks then use char instead of int.
    But you used int! Not char!

    It worked fine when I did that. It ran in a couple of minutes, no crashs no problems.
    I gig file created no problem!!
    With char, it works, sure. But that doesn't take away the fact that you're using one GB of memory for no reason. It's bloat, bloat, bloat, just bloat and a very, very, very poor example.

    On another system it would have greated a 4 gig file with no problems.
    Not on a 32-bit system, no.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #39
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by Elysia View Post
    It's still bad practice. When someone writes real program, they don't terminate the application that way.
    Are you intending that to be main or a utility function?

    Not intending it to be anything it's just a piece of code.
    If I wanted to use it in another program I would just copy the code in.

  10. #40
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by Elysia View Post
    Irrelevant.


    The problem isn't as simple as you think it is. Do you even know WHY it's limited?

    Poor operating system design perhaps????? (Just a wild stab).

  11. #41
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by esbo View Post
    Poor operating system design perhaps????? (Just a wild stab).
    No, unfortunately not.
    First, 32-bit means we can only address 4 GB of memory (0xFFFFFFFF), and secondly, Windows must reserve memory for its internal functions and for drivers and other specific things. Therefore, Windows reserves a big of memory for itself, which application cannot use. Thus you cannot use 4 GB memory on a 32-bit system. Not even Linux can.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #42
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by Elysia View Post

    With char, it works, sure. But that doesn't take away the fact that you're using one GB of memory for no reason. It's bloat, bloat, bloat, just bloat and a very, very, very poor example.


    He said he wanted to write gig of data to a file.
    I assumed he had one gig of data to write in some real world
    application. I cannot imagine anyone in their right mind would
    and to write one gig of 'x's in to a file.
    I was therefore giving an example of how to write the data at 'top speed'.
    So it aint bloat at all.

  13. #43
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by esbo View Post
    He said he wanted to write gig of data to a file.
    I assumed he had one gig of data to write in some real world
    application. I cannot imagine anyone in their right mind would
    and to write one gig of 'x's in to a file.
    I was therefore giving an example of how to write the data at 'top speed'.
    So it aint bloat at all.
    No, it's bloat. Reading one GB into memory and then writing it with one GB buffer is slower than reading chunks. Sorry.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  14. #44
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by Elysia View Post
    No, unfortunately not.
    First, 32-bit means we can only address 4 GB of memory (0xFFFFFFFF), and secondly, Windows must reserve memory for its internal functions and for drivers and other specific things. Therefore, Windows reserves a big of memory for itself, which application cannot use. Thus you cannot use 4 GB memory on a 32-bit system. Not even Linux can.

    My processor can address more than 4GB of memory.
    The fact windows cannot use it it probably down to the kind of programming
    style you adhere too.

    It is down to bad programming.

    Shockingly bad programming.

    My program on the other hand would run prefectly well on a machine capable
    of addressing more than 4GB of memory where it not restricted by a pile of
    crap called 'windows'.

    Mine is an example of programming of the very highest standard possible infact.

  15. #45
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by esbo View Post
    My processor can address more than 4GB of memory.
    Only 64-bit processors can in 64-bit mode and a 64-bit operating system!
    (Of course, there is the PAE, or whatever it's called, but it's not common and it's definitely not intended for consumer desktops.)

    The fact windows cannot use it it probably down to the kind of programming
    style you adhere too.
    NO! It's a processor limitation! Get your facts straight before you accuse someone!

    It is down to bad programming.
    NO!

    Shockingly bad programming.
    NO!

    My program on the other hand would run prefectly well on a machine capable
    of addressing more than 4GB of memory where it not restricted by a pile of
    crap called 'windows'.
    NO! Again, you should what little you really know. Get your facts straight - read up on how processors work before you start accusing me!
    A 32-bit pointer simply CANNOT hold any values higher than 4 GB.

    Mine is an example of programming of the very highest standard possible infact.
    It is one of the poorest example I have seen. In fact, I've seen newbies write better code.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. read / write binary files
    By Dark_Phoenix in forum C++ Programming
    Replies: 5
    Last Post: 06-21-2009, 07:56 AM
  2. Create Copies of Files
    By Kanshu in forum C++ Programming
    Replies: 13
    Last Post: 05-09-2009, 07:53 AM
  3. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  4. Linking header files, Source files and main program(Accel. C++)
    By Daniel Primed in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 11:46 AM
  5. Using c++ standards
    By subdene in forum C++ Programming
    Replies: 4
    Last Post: 06-06-2002, 09:15 AM