How to write files more faster in C

This is a discussion on How to write files more faster in C within the C Programming forums, part of the General Programming Boards category; Originally Posted by Elysia It's not listed as Microsoft-specific, though. If there's any other documentation available that you can check, ...

  1. #16
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    Quote Originally Posted by Elysia View Post
    It's not listed as Microsoft-specific, though. If there's any other documentation available that you can check, it should be easy to determine whether it's Microsoft-specific.
    If it is, then I guess you just have to use API.
    It IS listed

    The c, n, t, S, R, T and D mode options are Microsoft extensions for fopen and _fdopen and should not be used where ANSI portability is desired.
    http://msdn2.microsoft.com/en-us/lib...cb(VS.80).aspx
    See Requirements section
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  2. #17
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,165
    Yes, stupid Microsoft. They tend to hide away such information.
    Guess you'll have to rely on API after all.
    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.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  3. #18
    Registered User
    Join Date
    Jan 2007
    Posts
    330
    The flags can still come in handy when you know you will be writing windows only code anyway

  4. #19
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,165
    It only works in Visual Studio, so it's not portable code since it won't work with other IDEs or compilers.
    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.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  5. #20
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,607
    DevC++ / Mingw uses the Microsoft CRT DLL (MSVCRT.dll) - so MS CRT extensions could be used if you like.

    However, you need to use the Visual Studio 6.0 CRT documentation to see what's available:
    http://msdn2.microsoft.com/en-us/lib...92(VS.60).aspx

    gg

  6. #21
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    Quote Originally Posted by Elysia View Post
    It only works in Visual Studio, so it's not portable code since it won't work with other IDEs or compilers.
    ahem, Bloodshed, which uses GCC, supports WinAPI, so the code is portable to other IDE/Compilers, just not to other OS's, except Linux has windows emulation now, so nevermind, windows code is fully portable.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  7. #22
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Quote Originally Posted by abachler View Post
    windows code is fully portable.
    I wouldn't go that far.

  8. #23
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,165
    Quote Originally Posted by abachler View Post
    ahem, Bloodshed, which uses GCC, supports WinAPI, so the code is portable to other IDE/Compilers, just not to other OS's, except Linux has windows emulation now, so nevermind, windows code is fully portable.
    Not the API, but the Microsoft CRT extensions.
    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.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  9. #24
    Registered User
    Join Date
    Jan 2007
    Posts
    330
    AFAIK the CRT on windows comes in a Dll too, so its perfectly possible to use microsft extensions like the fopen flags from other compilers. You just need to link to the MSVCRTxx.dll

  10. #25
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, but it's still ONLY going to work that way in a Microsoft environment.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  11. #26
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Use a loop to fill pname with f's.
    Then use this.
    That is the fastest possible way.


    Code:
    FILE *dataptr;
    int pname[1000000000];
    
    datasave(){
    
    		if (	(dataptr=fopen("data.doc", "wb+" )) != NULL) {
    				fwrite(  pname, sizeof( pname   ), 1, dataptr);
    				fclose(dataptr);
    			
    		}
    		else {
    			
    			puts("\nCant creat datafile");
    			exit(2);
    
    		}
    	
    }

  12. #27
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,165
    Are you kidding us?
    pname is 4 x 10 ^ 9 bytes long, it's global, datasave doesn't return anything, you open for reading and writing and you write an unfilled buffer.
    Yes, it's really works well, doesn't it?
    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.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  13. #28
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by Elysia View Post
    Are you kidding us?
    pname is 4 x 10 ^ 9 bytes long, it's global, datasave doesn't return anything, you open for reading and writing and you write an unfilled buffer.
    Yes, it's really works well, doesn't it?
    Yes it does work. Global data should be gobal not local, hence it is global.
    Passing around 4 gigabytes of data within a program would be bordering on insanity.
    It is open for reading and writing because that is how it was used in the origninal
    program where the code was copied from. The user never implied that reading the file
    should be restricted so there was no reason to restrict it in the example.
    To do so would thus be rather pointless.
    There is nothing to return.
    It is implicit that the trivial matter filling of the buffer is not shown for brevity.
    The function rightly aborts immediately when it encounters a fatal error, this saves
    each call to the function duplicating the code unnecessarilly.

  14. #29
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,165
    Quote Originally Posted by esbo View Post
    Yes it does work.
    Does not work.
    4 x 1000000000 / 1024 / 1024 / 1024 = 3814,697265625 ~= 4 GB.
    Oops! Insta crash!

    Global data should be gobal not local, hence it is global.
    Global variables and global data should be avoided.

    Passing around 4 gigabytes of data within a program would be bordering on insanity.
    And what exactly do you think you're doing?

    It is open for reading and writing because that is how it was used in the origninal
    program where the code was copied from. The user never implied that reading the file
    should be restricted so there was no reason to restrict it in the example.
    To do so would thus be rather pointless.
    That is ridiculous. If the only thing you do is write, then only open it for writing.
    Otherwise consider adding a read or just a pseudo /* Read something here */ comment.

    There is nothing to return.
    Yes, there is. Void.

    It is implicit that the trivial matter filling of the buffer is not shown for brevity.
    Then add a pseudo /* Fill buffer or reading something here */

    The function rightly aborts immediately when it encounters a fatal error, this saves
    each call to the function duplicating the code unnecessarilly.
    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.
    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.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  15. #30
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by Elysia View Post
    Does not work.
    4 x 1000000000 / 1024 / 1024 / 1024 = 3814,697265625 ~= 4 GB.
    Oops! Insta crash!
    Nope no crash.
    You are asuming the integer size is 4, I am assuming it is 1.
    Eitherway no crash.

Page 2 of 6 FirstFirst 123456 LastLast
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, 10:46 AM
  5. Using c++ standards
    By subdene in forum C++ Programming
    Replies: 4
    Last Post: 06-06-2002, 09:15 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21