![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
Comments on comments stripper
I've made a comments stripper.
Please take a look and comment (post a reply) if my code is still incorrect, or if you have any enhancements or other comments. I think I got it all correct now, but in the first version I thought I didn't have any bugs. But since then I've made 2 changes (fixed 3 minor bugs) to the code. Apparently my first test file wasn't so good. I have tried more files now and all worked, but maybe I am still missing something.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4
![]() |
You're reading the whole file in a single go. That can cause problems if the file is large. I think you should read the file in blocks.
__________________
PFO - My daily dose of technology. |
|
|
|
|
|
#3 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Maybe he should. One the other hand, such a large source file represents suitable punishment for the jerk that produced it.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#4 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: New Mexico
Posts: 228
Rep Power: 4
![]() |
InfoGeek -
That's why there are swapfiles in UNIX and Windows. A lot of utilities in UNIX run sysconf and then stat on the file first to decide if they will be forced into low-level i/o that is limited to really small blocks - kinda like line by line. Otherwise they will use pretty large chunks. Modern disks can return 1MB blocks virutally as fast as 16K blocks. Most of the delay is waiting for previous i/o requests to clear. The underlying support for stdio functions usually reads big chunks from files to start with. Then they buffer i/o access in small pieces to the process. I don't think I've ever seen a 4MB C source file anyway. |
|
|
|
|
|
#5 | ||
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
Quote:
Quote:
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
||
|
|
|
|
|
#6 | |
|
Professional Programmer
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4
![]() |
Quote:
![]()
__________________
PFO - My daily dose of technology. |
|
|
|
|
|
|
#7 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Just an addendum to what Jim is saying: it's the reason I never comment to an OP about reading the file byte-by-byte instead of larger chunks. The penalties for doing so are mostly removed by the process of OS buffering in conjunction with library-function buffering. I also try not to think about systems where tain't so -- it makes my teeth ache.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|