|
Hi,
I need to get the size of many (can be over 5000) files very fast. What would be the fastest way to do this? Also, durring the runtime of the application, it will be getting file sizes every second or so.
As far as I know, I can use GetFileSize or I can fseek() to the end of a file.
Thanks for the help! I'm bonkrd
|
|
|
|
|
Doesn't really matter because the most expensive part is opening the file...
|
|
|
|
|
The file are the file in the Temporary Internet Files for the current user (\Documents and Settings\%USER%\Local Settings\Temporary Internet Files) folder. They are actually traversed with the Win32 Cache functions, but they don't give the correct file size (or just most of the time they leave the file size field of the file info structure to 0)
Since these are cached files, isn't their information cached somewhere also?
-- Andrei B (andreib.com/blog)
|
|
|
|
|
If you wan't the file size without opening the files (and I'm sure that's what you want) use the stat() or _stat() function.
stat() fills a stat struct and one of the members in that struct is the file size.
-- modified at 1:27 Tuesday 25th October, 2005
|
|
|
|
|
try to use CFileFind.
karo
|
|
|
|
|
andreizilla wrote: Also, durring the runtime of the application, it will be getting file sizes every second or so.
Why poll for something that may not exist (as frequently as one second)? Wouldn't it make more sense to let the OS tell you when the size of a file has changed?
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
Use FindFirstFile,FindNextFile and FindFileClose method, it return WIN32_FIND_DATA structure which DWORD nFileSizeHigh, DWORD nFileSizeLow member contain size of file.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
hi! I'm a college student but on spare time like programming, I've been programming since I was ten, and this summer I'm getting my hands on a big C++ programming project. I'm currently on the "planning stage" and need help on the following:
First a few things you should know in order to help:
---------------------------------------------------
-Most of the coding is to be done on a 486dx2 8MB RAM 800MB HDD notebook, which is able to run W95 and DOS. Graphic mode works. I haven't tried Linux, but I don't think it would be practical, as I need as much HDD I can get for project sample data.
-My main goal is efficiency meaning speed (and results, though not relevant here) and compatibility with at least every Windows-DOS PC (allowing 640x480x256) and if possible Linux.
-This program will NOT use MFC, but needs to be able to init graphic mode at 640x480x256. I want specifically this as it looks pretty standard for compatibility with older PCs.
My problems:
------------
#1:
I was thinking of using pure ASM code to "init graph", "put/get pixel", etc, but i've been told that not all OS's will allow this (at least not all will allow me to write directly to video memory).
What should I do about this? Should I use some "graphics.h" or such?
#2:
I'll be doing heavy HDD I/O as the main task in this program will be file data analysing. I've read I should open files in binary mode as it is supposed to be the faster way to perform reading and writing. Is this true? What would be the most efficient way?
#3:
I need a very light and very specific Window-GUI (by specific I mean I won't need many controls and they will need to be adapted to the program's needs), so I was thinking of making one of my own. Taking out the "complexity" issue which is being taking care of, the real doubt here is: Will it truly be more efficient given I would use ASM for graphics routines, mouse routines and perhaps also keyboard routines? I point to that perhaps any other GUI already out there uses some other sophisticated techniques which would make them faster anyway... I should add that I'm not thinking of moveable/resizable windows, as it's more about n-criteria sorting flexgrids and checkable filelistboxes...
#4:
Some libraries already made objects from my project are currently working on VC++. Now, as you know, VC++ won't fit my 486 , I've thought about "CommandLineTools.exe" (8,5MB) from borland but it seems to lack of some really important libraries such as "conio.h"!?!? (goodbye getch, kbhit ) So what I'm asking is: Which C++ distribution will fit best my needs, given all you've read so far? I've really enjoyed BCC55 (CommandLineTools.exe), is there any way I could use it? Perhaps extending the amount of libraries? What about GCC (the DOS version)? GCC should be the most compatible...
#5:
What are the main incompatibilities I should be aware of between XP, Dos 16bit and Linux? And, what key things won't be running on my 486?
#6:
As the visual interface will be graphic mode, I'll need fonts for displaying text, and MANY text will be displayed. I was thinking of making my own "font printf/cout" routines based on ASM putpixel, mostly because I don't need more than 3 different sizes nor more than 2-3 different fonts. Is this idea viable, once again taking out the complexity issue? Are there any font displaying libraries both light and simple to use out there?
#7:
While secondary to the main functionalities of the program, I will need to show BMPs, play WAVs, timing events and implementing sprites/masks. I've read there are many packages labeled as "Game Libraries" which do all this stuff, but all the ones I've found offer too many extra features which make the package too big and complex. Does someone know of a specific package which both handle my required features and is light in size/complexity? Will it work on my 486??
THX A LOT IN ADVANCE!!
Mariano Lopez-Gappa (20) from Argentina
|
|
|
|
|
hi,
I'd written a program about 3 years ago whose requirements were very similar to urs. Since then I've never programmed in any other language other than VC. Even then, though i've forgotten a lot of things, lemme answer ur queries:
1. The problem with "ALL" OS is that most of them run in protected memory mode, hence they wud not allow u to directly write to memory. But there are ways, and prob'ly they are OS specific.
2. yeah, binary file read/write is almost always faster.
3. u may write ur own library. For 640x480x256, u might be thinking of using SVGA, though I found the SVGA a bit slower - using banking and all those stuff. I am pretty sure old monitors wont support SVGA.
4. Never been into those thins
5. As long as u stick to C++, there wont be any incompatibilities, but when jumping to asm, man - there are almost always incompatibilities.
6. For displaying fonts really fast, I'd preffered my own bitmapped fonts rather than the font libraries.
7. Showing BMP's and playing WAV's are pretty easy tasks, u can google for the algos and demo codes.
Hope this wud help u.
"Do first things first, and second things not at all."
— Peter Drucker.
|
|
|
|
|
Mariano Lopez-Gappa wrote: I was thinking of using pure ASM code to "init graph", "put/get pixel", etc, but i've been told that not all OS's will allow this (at least not all will allow me to write directly to video memory).
I don't see how you can target linux as well. IMO you should use DirectX for the fastest possible video. I don't think that asm is a good move, from a maintainability standpoint as much as anything, but I also believe that DX handles differences between video cards for you - you don't want to do that in asm.
Even creating a DIBSection will give you direct memory access to bitmap bits, although running in 256 colour mode means you're using a palette, which is always more messy than 16 bit or higher.
Mariano Lopez-Gappa wrote: read I should open files in binary mode as it is supposed to be the faster way to perform reading and writing.
That's possible, are you reading binary data, or text. You should use the class that's optimised for the sort of data you want to read. Worry about speed as it becomes an issue, and do your own tests to see what works best.
Mariano Lopez-Gappa wrote: Will it truly be more efficient given I would use ASM for graphics routines, mouse routines and perhaps also keyboard routines?
No. Using Win32 is as close to the machine as you need to get.
Mariano Lopez-Gappa wrote: Which C++ distribution will fit best my needs, given all you've read so far?
The command line compiler that comes with VC.
Mariano Lopez-Gappa wrote: What are the main incompatibilities I should be aware of between XP, Dos 16bit and Linux?
DOS means writing a text only program, or doing the graphics by hand. Linux will have it's own libraries for graphics. I don't see you targetting all three, without an abstraction that allows you to write three presentation layers.
Mariano Lopez-Gappa wrote: While secondary to the main functionalities of the program, I will need to show BMPs, play WAVs, timing events and implementing sprites/masks
Windows will let you show BMPs, play WAVs and run a timer.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I think Borland Turbo C++ 3 should get the job done, but you will stay in 16-bit, which means a maximum of 640KB of RAM, out of which you will probably get 500KB. That is the main bottleneck.
1- You can use the SVGA modes. For 640x480x8, the mode is 0x101. There are lots of resources on the net for any graphics modes. Most PCs 486 dx2 will allow that mode (0x101). It actually depends on the Graphics Card RAM. You should have at least 1MB. However, any modern OS will not allow you to use these display modes. You may not use the graphics.h which comes with Turbo C.
2- Binary is faster.
3- About the GUI, you won't get anything. You will not even get basic I/O routines like cout, printf etc, or any GUI stuff like textout, outtextxy either. You will need to do them yourself. ASM may be used, but needed only for mouse-support, and to change the pallete (8-bit modes need to use palletes for bmps). If you are thinking about grids and listboxes, then it is a lot of work. I created such a library some years ago, it had editboxes, vector fonts, radio buttons, checkboxes, command buttons, keyboard, mouse support. It was hard work. And you will need to display the mouse cursor yourself also.
4- I have never used Linux, so I can't comment, but Borland Turbo C++ 3 or 3.1 should do. It has conio.h for getch, kbhit etc.
5- The 16-bit program will run well on a 486. But it may or may not run on Win2000, XP.
6- See (3) above. You might find such a library on the net.
7- For BMPs and Wavs, it is very cool for DOS programs to display pics and use the sound card. The bmp algorithm is easy to find on the net, but there is the limit of ram you can use. About wav files, find documentation for the sound card you are using, like Sound Blaster; Their docs are easy to find.
Hope that helps a little.
this is this.
|
|
|
|
|
First of all thx for your reply and thx to the other 2 guys replies. All of you helped a lot.
New questions have arised due to replies:
#1: My knowledge of technical differences between 16-32-64 bits is little or none...but I'm definitely gonna need more than 640K lol. There's gotta be a way to bypass the 640K limit! I thought mallocating on C and "New-ing" on Pascal allowed use of extended memory...
Well, if it just can't be done, I can work it out by not exceeding the limit while I use the 486...resigning compatibility with it, it's ok, it wasn't that big deal...nor was Linux compatibility.
It seems I'm gonna need a 32-bit compiler (though I don't really know much what it means), perhaps this is what "BBC32" meaning was (32 bit). What compiler should I use given the new circumstances? Will it still run on the 486?
#2: The graphic issue seems problematic, seems I'll have to make a first version working on the 486 and then the release one. So, given the first one is ok, what would be the better choice for graphic mode compatibility between W98-Me-NT-2000-XP? I should add that there's no way Ima use MFC nor DirectX.
Thx in advance!!
Mariano Lopez-Gappa
|
|
|
|
|
i use thread to animate an opengl object on a dialog box, it use "for" to loop and make a animate,
if not using thread, i use UpdateData(FALSE) and is see animation is moving,
BUT if i use thread i did see the movement, it see if i press button and other activity, any body help me ... plz...
|
|
|
|
|
Please state the question more clearly, possibly post some code.
John
|
|
|
|
|
try to use 'windows messages' to interact with dialogs. a good idea is to use WM_TIMER / SetTimer ...
karo
|
|
|
|
|
Hello,
I'm interested in writing a program that reads an XML input file, and then based on the content of that file, writes another program which is then compiled. I imagine that I'd do this by defining an ofstream and literally writing the new prorgram line by line. The "preprocessing" program would look something like this:
ofstream out("program.cpp");
out << "int main()" << endl;
out << "{" << endl;
out << "return 0;" << endl;
out << "}" << endl;
Where I'd have to write the relevant functions for my problem. I'd then run the proprocessing program and compile the "new" program using a batch file.
My question is this: Is there a name for this type of programming? I'd like to read up about it in general before I dive in but the searches I have done haven't revealed much. Also, does MS VC++ provide any helpful methods for writing such programs?
Thanks,
--Jordan Atlas
|
|
|
|
|
Its called code generation and its a pretty complex topic. Lots of high end programming tools do this. Rational Rose for example can generate code from UML models.
You could look at using Lex.
You could create an object model to represent the C++ entities (classes, function, variables etc etc). A program would be represented by a tree like structure of these objects. Each of these classes could construct itself from the xml and then write iteself to the stream. You could take it a step further and make this object model non language specific then apply formatting objects for the language you want (C++, c#, Java) this would mean however that your xml representation would be limited to features common to these languages.
|
|
|
|
|
Hello,
Is the XML file a something you can change? I mean, if you can influence the data in the XML file, it may be better to stick to scripts. You'll avoid mass complexity of generating C++ code.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Hi,
Thanks for the replies.
The XML file is a representation of a model (variables and equations). The program that I'm trying to have it automatically write will solve the system of equations represented in the XML file. I'm trying to do this so that the (compiled) new simulation program will be faster than if I repeatedly sampled information in the XML file...
--Jordan
|
|
|
|
|
So you are doing this for performance reasons. Than scripts are probably too slow for you too.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Hi,
I have a project which i am unable to do myself.It is not a very long project but because of the time constraint,I would like it to be completed at most by the 7th of November.
The specifications of the project are as follows:
I actually am developing a hearing aid and now the problem is in real time implementation of it.
1. I have to capture speech coming in through "mic in" port of the computer.
2. The captured speech would pass through a module(consisting of filters and Fourier transforms)..which i have written below.
3. The output through my module has to be played back out through the "mic out" port of the computer.
Code is :
#include <stdio.h>
#include <math.h>
#include <string.h>
double wdata[13]; //required for the FFT
double datafft[8192]; //length required is twice the inverse FFT
double x[295000]; //input data vector,maximum,length
int expo = 12; //required for the FFT
int main ()
{
double pi,ex,temp,theta1,coefa,coefb,G;
double X2,W1,bf,phikb,phia,phib;
double phi[1260],XR[4096],XI[4096],X[4096],XM[4096];
double w[512]; // vector of hamming window values
double ret[4096]; // vector of the inverse FFT returned data
double x1[512],x2[512],f[512];
double G1;
int a,i,j,k,m,n,FL,NW,L,l,q1,q2,kb,ks,ke;
double sr = 25000.0; // sampling rate
int CF = 15; // compression factor,CF:1
int hfru = 10500; // high frequency range upper limit
int hfrl = 4400; // high frequency range lower limit
int N = 2048; // number of frequency samples,top half
int ND = 512; // length of input data
int M = 4096; // length of inverse FFT
FILE *fp;
fp = fopen("ELPHRG01.WAV","r+b");
i = 0;
*/
while((fscanf(fp,"%f/n",&x[i++])) != EOF);
fclose(fp);
FL = i;
pi = 4.0 * atan(1.0);
ex = exp(1.0);
NW = 512;
W1 = 0.5;
l = 0;
L = 1;
for (n=0; n < NW; n++) {
theta1 = (2 * pi * n) / (NW - 1);
w[n] = W1 - (W1 * cos(theta1));
}
for (n = 0; n < NW; n++) {
x2[n] = 0.0;
}
bf = sr / (2 * CF); // break frequency
phikb = (pi * bf) / (sr / 2); // angle of break frequency
kb = N / CF; // number of samples from DC to break
phia = (hfrl / (sr /2 )) * pi; // high frequency region starting angle
phib = (hfru / (sr /2 )) *pi; // high frequency region ending angle
coefa = 0.00799;
coefb = -0.3722072;
//1. Obtain a windowed Segment of the input data
for (a = 1; a < 2 * FL / NW + 1; a++) {
for (m = 0, n = 1; m < NW; m++, n++) {
f[m] = w[m] * x[n];
}
}
//2. Obtain Nonlinearly Compressed and Transpossed frequency samples
for (k = 0; k < 150; k++) {
temp = coefa * k;
phi[k] = pow(ex, temp) + coefb;
G = pow(ex, temp);
G1 = G * sqrt(G) + 6;
XR[k] = 0.0;
XI[k] = 0.0;
for (n = 0; n < ND; n++) {
XR[k] = XR[k] + f[n] * cos(phi[k] * n);
XI[k] = XI[k] + f[n] * sin(phi[k]*n);
}
XR[k] = G1 * XR[k];
XI[k] = G1 * XI[k];
}
//3. Pad zeros in the center of the Spectrum
for (k = 150; k < M - 150; k++) {
XR[k] = 0.0;
XI[k] = 0.0;
}
//4. Form the Complex conjugate part of the spectrum
for (k = M - 150 + 1; k < M + 1; k++) {
XR[k] = XR[M-k];
XI[k] = -XI[M-k];
}
//5. Convert from Polar to rectangular for the inverse FT
for (i = 0; i < M; i++) {
j = 2 * i;
k = j + 1;
datafft[j] = XR[i];
datafft[k] = XI[i];
}
//6. Call the FFT
f_init(); //I need to implement this FFT function in C++ rather than Foxpro
MAIN_();
//7. Obtain the inverse FFT from the FFT call
ret[0] = datafft[0] / M;
for (i = 2244; i < 2756; i++) {
j = 2 * i;
k = 2 *M - j;
ret[i+1] = datafft[k] / M;
}
for (k = 0; k < 512; k++) {
ret[k] = ret[k+2244];
}
// Multiply by the hamming
q1 = a / 2;
q2 = q1 * 2;
if (q2 == a) {
for (i = 0; i < 256; i++) {
X2 = ret[i] * w[i] + x1[i + 256];
printf("%f\n",X2);
}
for (i = 256; i < 512; i++) {
x2[i] = ret[i] * w[i];
}
} else {
for (i = 0; i < 256; i++) {
X2 = ret[i] * w[i] + x2[i + 256];
printf("%f\n",X2);
}
for (i = 256; i < 512; i++) {
x1[i] = ret[i] * w[i];
}
}
l = (NW * L / 2);
L = L+1;
return 0;
}
MAIN_()
{ //This is again using Fox Pro but i am not sure
fft2c_(datafft,&expo,wdata);
return 0;
}
So,in all i just need code development in C++ to capture speech and play it back and a slight modification in my module to make it compatible.
If somebody can please help me out,I am even willing to pay for the project.
Thanks,
Student
-- modified at 21:21 Monday 24th October, 2005
|
|
|
|
|
There is a ton of source code online for fourier transforms, it's a common problem, and one that is well documented.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Ya, but could you help me out in implementing the code which I have written in real time ?
|
|
|
|
|
Real time ? I doubt it. I'm sure I could do it, but not in the timeframe that I could give to helping someone on a forum, sorry. You'd do better to look for a solution than hope for someone to dedicate time to writing this for you specifically.
If you're calling functions in Foxpro somehow, you'll definately gain speed from moving to C++.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I pulled the following lines from my C program, which captures video and audio, and saves it to a file.
I have an array of video and audio buffers, each 33.3 mSec (NTSC) or 40 mSec (PAL), and I capture to these in turn, wrapping round to the first when I finish the last buffer. When the user stops capture, the buffers can be stored as an AVI file with sound.
I have NOT done any audio output stuff, so I cannot give sample code there!
Use the code given below as hints - I found all of this on the MSDN CDs that came with Visual Studio 6. I have left out most of the error detection code.
uiNumWaveInDevices = waveInGetNumDevs();<br />
<br />
waveInGetDevCaps(0, &WaveInCaps, sizeof(WaveInCaps));
<br />
if (!(WaveInCaps.dwFormats & WAVE_FORMAT_1M16))<br />
<br />
AudioFormat.wFormatTag = WAVE_FORMAT_PCM;<br />
AudioFormat.nChannels = 1;
AudioFormat.nSamplesPerSec = 11025;
AudioFormat.nBlockAlign = 2;
AudioFormat.wBitsPerSample = 16;
AudioFormat.nAvgBytesPerSec = 11025 * 2;
AudioFormat.cbSize = 0;
<br />
hAudioInDevice = NULL;<br />
<br />
uiReturn = waveInOpen(&hAudioInDevice, 0, &AudioFormat, 0, 0, CALLBACK_NULL);<br />
if (uiReturn != MMSYSERR_NOERROR)<br />
<br />
uiAudioBufferMaxSize = AudioFormat.nSamplesPerSec * AudioFormat.nBlockAlign * AudioFormat.nChannels / 25;<br />
<br />
AudioHeader[uiCounter].lpData = GlobalLock(GlobalAlloc(GMEM_FIXED, uiAudioBufferMaxSize));<br />
<br />
for(uiCounter = 1; uiCounter<uiMaxNumOfFrames; uiCounter++)<br />
pAudioDataBlock[uiCounter] = pAudioDataBlock[0] + uiCounter * uiAudioBufferMaxSize;<br />
<br />
uiAudioBufferActualSize = uiAudioBufferMaxSize;<br />
for(uiCounter = 0; uiCounter<DEF_NumberAudioDeviceBuffers; uiCounter++)<br />
{<br />
AudioHeader[uiCounter].dwBufferLength = uiAudioBufferActualSize;<br />
AudioHeader[uiCounter].dwBytesRecorded = 0;<br />
AudioHeader[uiCounter].dwUser = 0;<br />
AudioHeader[uiCounter].dwFlags = 0;<br />
AudioHeader[uiCounter].dwLoops = 0;<br />
uiResult = waveInPrepareHeader(hAudioInDevice, &(AudioHeader[uiCounter]), sizeof(WAVEHDR));<br />
}<br />
<br />
<br />
for (i = 1 to 5)<br />
waveInAddBuffer(hAudioInDevice, &(AudioHeader[uiNextIndexToQueue]), sizeof(WAVEHDR))<br />
<br />
if (bThisIsFirstBuffer)<br />
waveInStart(hAudioInDevice);<br />
<br />
<br />
while (!(AudioHeader[uiAudioNextIndexToProcess].dwFlags & WHDR_DONE))<br />
;<br />
<br />
<br />
memcpy(pAudioDataBlock[uiNextIndexToProcess], AudioHeader[uiAudioNextIndexToProcess].lpData, uiAudioBufferActualSize);<br />
<br />
waveInAddBuffer(hAudioInDevice, &(AudioHeader[uiAudioNextIndexToQueue]), sizeof(WAVEHDR))<br />
<br />
<br />
waveInStop(hAudioInDevice);<br />
<br />
for(uiCounter = 0; uiCounter<DEF_NumberAudioDeviceBuffers; uiCounter++)<br />
{<br />
while (!(AudioHeader[uiCounter ].dwFlags & WHDR_DONE))<br />
;<br />
waveInUnprepareHeader(hAudioInDevice, &(AudioHeader[uiCounter]), sizeof(WAVEHDR)))<br />
GlobalFree(GlobalHandle(AudioHeader[uiCounter].lpData));<br />
}<br />
<br />
GlobalFree(GlobalHandle(pAudioDataBlock[0]));<br />
<br />
GlobalFree(GlobalHandle(pAudioDataBlock));<br />
<br />
waveInClose(hAudioInDevice);
|
|
|
|
|