Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Oops.

Did not mean to keep this question,
but if someone wants to answer,
nicely,
then that is OK.





I have two ways that I am looking at the file length. Which is better?

Use:

If I want to update some software for my uncle's old saw mill machine that has a programmable controller with C, and I want to code it in C or C++98 or in C++03, nothing newer:

I am doing a test on an old Windows XP Pro 32 bit system with every (at the time of installation) code page installed, and with CodeBlocks 17.12 and GCC of 5.1 .


Explaination for some people:

A DWORD is a 32-bit unsigned integer (range: 0 through 4294967295 decimal).

Using two of them together is one way of representing a 64-bit value.

In the event the value being represented fits into 32 bits just fine, the high-order DWORD will then be zero.

If the value is larger than fits into 32 bits then the low-order DWORD will be the remaining.


References and origins for some of my wording for some people:

See: https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-dtyp/262627d8-3418-4627-9218-4ffe110850b2

See: https://stackoverflow.com/questions/2995251/why-in-c-do-we-use-dword-rather-than-unsigned-int

See: https://forums.codeguru.com/showthread.php?465171-high-or-low-order-DWORD (very nice explaination of high vs low order).



I am using GetFileSize instead of GetFileSizeEx because my setup has difficulties with GetFileSizeEx. I know that Microsoft says, "It is recommended that you use GetFileSizeEx." But, it does not work well for this setup.



Here are the two ways. Please tell me which is best, or fastest, or more stable, and please explain why you personally think that.

One way I use a PDWORD. The other way I use a &DWORD.

Better? Faster? More stable? Specifically, why do you personally think that?

Thank you.

What I have tried:

// File name
const wchar_t* TheFile_to_READ;

TheFile_to_READ = L"utf8_UsingByteOrderMark_C_天堂.txt";


HANDLE HANDLE_Of_File_to_READ;

HANDLE_Of_File_to_READ = CreateFile(TheFile_to_READ, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);


DWORD DW_001;

const unsigned long long DW_fileLength_001 = GetFileSize ( HANDLE_Of_File_to_READ, &DW_001 ) ;

long unsigned int DW_LUI_001 = DW_001;

string ppppBLA = to_string(DW_LUI_001);



// or maybe

PDWORD PDW_002;  // a pointer to a DWORD   or   unsigned integers (32bit)   or   uint's
                 // a pointer to possibly two WORD's or two 32 bit WORD's

const unsigned long long PDW_fileLength_002 = GetFileSize ( HANDLE_Of_File_to_READ, PDW_002 ) ;

long unsigned int LUI_002 = (DWORD)PDW_002;

string pppp = to_string(LUI_002);
Posted
Updated 6-Jul-22 9:52am
v9
Comments
Dave Kreskowiak 6-Jul-22 0:06am    
I rolled the question back to the original. Editing it to remove the question after an answer has been posted is just rude.
merano99 6-Jul-22 7:42am    
You said it. Unfortunately noticed several times, and also resistant to advice. He doesn't get any more answers from me. Maybe answers about uninitialized pointers are too hard.
Member 15078716 6-Jul-22 15:08pm    
@Dave Kreskowiak, No. It is not rude. It was my question, not your's. I gave two examples, which I know the second is illogical, therefore no need to even ask about it. It is rude of you to interfere in someone else's question. An edit is fine and within the scope of this site. I wrote the question wrong. I noticed my mistake was illogical and it was wrong enough that I did not want to ask it. That does not call for an "edit". It calls for removing the question EVEN if some spammer posted to my question and did not even come close to answering it.

Furthermore:
At the bottom of this page it says, "Read the question carefully",
and "Insults are not welcome",
and "Provide an answer or move on to the next question."

You said, "There are no problems with GetFileSize and GetFileSizeEx on machines." So, OK. That is nothing new to say and it does not explain your non-answer as to which is better. I did not say that my machine had problems with these. I said, "I am using GetFileSize instead of GetFileSizeEx because my setup has difficulties with GetFileSizeEx. I know that Microsoft says, "It is recommended that you use GetFileSizeEx." But, it does not work well for this setup." Get it? Can you read or do you just spam with fast blather to get more points on this site?


You said, "The difference between the two is GetFileSize will only return an unsigned, 32-bit value, thus there's a limit to the size of the file it can return, 4,294,967,295 bytes. The Ex version returns a LARGE_INTEGER structure, which is two DWORDS." That has nothing to do with what I asked. That did not support your non-answer.

You said, "The only problem with using it would be the code you're writing to use it, not system related." I was not using GetFileSizeEx in the code of the question part. Again, are you simply blowing hot air to get some more points on your total for answering another question, although very wrongly answering? Again: That has nothing to do with what I asked. That did not support your non-answer.

You said, "As for the two types you're using, PDWORD and &DWORD, there is no difference. PDWORD means "pointer to a DWORD", or the address of a DWORD variable. &DWORD means essentially the same thing. It's an address of a DWORD." I already said that a PDWORD is, "a pointer to a DWORD". Again: That did not support your non-answer.

You have still not given a simple chosen answer. It was so easy. The second example, as CPallini said, "On the other hand, PDW_002 is an uninitialized pointer (i.e. points to garbage)." I was asking about my choice of those two. I have found that the uninitialized pointer was giving me nothing in return.

CPallini chose and gave logic that readers years from now may benefit from. You did not choose. You plagerized my question in your make believe support to a non-choice and you have still not chosen. -5 to your answer. -5 to your rolling back my question.

I think that you are a spammer Dave Kreskowiak.

No thanks for your answer.


Dave Kreskowiak 6-Jul-22 15:13pm    
NEITHER is better. One returns a 32-bit value and the other returns a pair of 32-bit values to make a 64-bit value. There is no speed advantage or stability advantage of either function.

Deleting a question after an answer has been posted to it is rude because now there's answers out there and no question, thereby defeating the points and discussions of the answers.
Member 15078716 6-Jul-22 15:30pm    
@Dave Kreskowiak, OK now I see logic to keeping a messed up question on the system.

I could have simply added at the beginning something like, "Oops. Did not mean to keep this question, but if someone wants to answer, nicely, then that is OK."

Thank you.


There are no problems with GetFileSize and GetFileSizeEx on machines.

The difference between the two is GetFileSize will only return an unsigned, 32-bit value, thus there's a limit to the size of the file it can return, 4,294,967,295 bytes. The Ex version returns a LARGE_INTEGER structure, which is two DWORDS.

The only problem with using it would be the code you're writing to use it, not system related.

As for the two types you're using, PDWORD and &DWORD, there is no difference. PDWORD means "pointer to a DWORD", or the address of a DWORD variable. &DWORD means essentially the same thing. It's an address of a DWORD.
 
Share this answer
 
The first approach is correct. The second one is a blunder.
From GetFileSize function (fileapi.h) - Win32 apps | Microsoft Docs[^]:
[out, optional] lpFileSizeHigh

A pointer to the variable where the high-order doubleword of the file size is returned. This parameter can be NULL if the application does not require the high-order doubleword.

Now, &DW_001 is the address of the DW_001 variable.
On the other hand, PDW_002 is an uninitialized pointer (i.e. points to garbage).

Moreover,
Quote:
long unsigned int LUI_002 = (DWORD)PDW_002;
is a plain wrong statement.
 
Share this answer
 
v2
Comments
Member 15078716 6-Jul-22 14:46pm    
@CPallini, To the point and you explained very well.

Thank you.
CPallini 6-Jul-22 16:21pm    
You are welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900