|
Well I learn most of things by experimenting. And that sentence was not meaningless it had a very specific purpose and I think it served its purpose very well.
Fine this is my last reply to you. I am not getting paid to answer here, I like helping others.
-Saurabh
|
|
|
|
|
Actually, if the file system is NTFS, then really short files are completely contained in the MFT itself and do not take up any clusters outside of the MFT.
For some good info on file systems, download JkDefrag version 3.36 (the last open source version) and read both the commentary and the code.
Dave.
|
|
|
|
|
Thanks. I use JkDefrag, now MyDefrag, quite frequently but didnt knew its documentation has information about file system also.
-Saurabh
|
|
|
|
|
In NTFS, a very small file just gets stored in the directory entry. So the cluster size "problem" doesn't happen.
Iain.
I have now moved to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), or need contract work done, give me a job! http://cv.imcsoft.co.uk/[ ^]
|
|
|
|
|
File size is the amount of data you can read from the file, i.e. how many bytes ReadFile() would return. It is affected by WriteFile, SetFileSize etc.
The file size on disk is the amount of storage actually requried to hold the file. There are many factors affecting that:
Disk clusters - disks are allocated in clusters (e.g 4KB blocks). In thsi case, even a 5 byte file will occupy 4K on disk.
File System Compression
Sparse files - some file systems, like NTFS, allow "sparse files", where long runs of 0 data are not stored.
Alternate Data Streams - on some file systems such as NTFS, each file can contain multiple "data streams". The data you "expect" - like the text in a text file - is the default stream. MS uses alternate data streams e.g. to store document properties, the "this file was downloaded from the eeevil internet" flag etc. They are quite cool, but limited to file systems that support them.
Calculating these sizes is tricky.[^] As Raymond Chen notes, there is no straightforward API for that, because how to calculate the size largely depends on the reason why you need to know the size. (Backup storage amount? percentage of disk occupied? Should alternate streams be included? etc.)
Personally, I love the idea that Raymond spends his nights posting bad regexs to mailing lists under the pseudonym of Jane Smith. He'd be like a super hero, only more nerdy and less useful. [Trevel] | FoldWithUs! | sighist
|
|
|
|
|
Your are right.
But, anyway, file-manager displayed "Size on disk", by what functions?
|
|
|
|
|
The value you see is calculated by the shell, but AFAIK the shell does not publish the algorithm it uses, nor does it expose a function giving you this information. The other reply is a good first shot at the value, but it's not guaranteed to be identical with what explorer shows.
Btw: replying to others with "Answer question or go away." gives yo ua good chance to get no answer at all.
This is a very rude and unfriendly reply, and it sounds like you are not interested in solving the problem yourself.
Personally, I love the idea that Raymond spends his nights posting bad regexs to mailing lists under the pseudonym of Jane Smith. He'd be like a super hero, only more nerdy and less useful. [Trevel] | FoldWithUs! | sighist
|
|
|
|
|
includeh10 wrote: But which function gets "Size on disk"?
There are no standard API functions which return the storage allocation for a file on the disk. There are many variables which have an effect on file storage size. For standard non-compressed and non-sparse files you can calculate it something like this:
#include <sys\types.h>
#include <sys\stat.h>
__int64 GetFileSizeOnDisk(LPCTSTR szPath,LPCTSTR szDriveLetter)
{
struct _stat64 st;
DWORD dwClusterSize = 0;
DWORD dwSectorsPerCluster = 0;
DWORD dwBytesPerCluster =0;
GetDiskFreeSpace(szDriveLetter,&dwSectorsPerCluster,&dwClusterSize,NULL,NULL);
dwBytesPerCluster = dwClusterSize*dwSectorsPerCluster;
int err = _tstat64(szPath, &st);
return err != 0 ? LLONG_MIN : st.st_size+dwBytesPerCluster-st.st_size%dwBytesPerCluster;
}
Note that very tiny files on an NTFS partition which are less than 50% of 1 cluster have a high probability of being stored directly in the $MFT which makes the function above have no meaning. There may also be alternate file streams associated with the file which would technically also add to the total storage allocation. For a complete solution it should be possible to get all volume storage allocation by using the FSCTL_QUERY_ALLOCATED_RANGES[^] Control Code.
Best Wishes,
-David Delaune
|
|
|
|
|
Problem : To construct a C++ code from a given Visual Basic String.
Frontend Application : Visual Basic
Backend Application : C++
Example1:-
Given Argument Is: Visual Basic String:
if (S>K) then S-K else 0
Result Should Be: C++ Code:
if(S>K) return S-K; else return 0;
End of Example1.
Now, from above example we find that there is if..else condition as well as an expression into it. There may be a case where i may
have nested condition or some math functions into it.
Example2:
Given Argument Is: Visual Basic String:
if (S>(K*V)) then Exp(S)-Sqrt(K) else if(S<k) then="" k-s="" else="" 0
<b=""> Result Should Be: C++ Code:
if(S>(K*V))
return (exp(S)-sqrt(K));
else if(S<k)
return="" k-s
="" else
="" 0;
end="" of="" example2.=""
so,="" there="" may="" be="" any="" random="" vb="" string="" which="" need="" to="" converted="" into="" executable="" c++="" code.=""
<div="" class="ForumSig">Thanks & Regards
Vishrant Shah
|
|
|
|
|
Yes, that's a very nice homework problem. I think you have stated it very well. Let us know what you come up with.
|
|
|
|
|
Vishrant Shah wrote: So, there may be any random VB string which need to be converted into executable C++ code.
Do you want to convert the code only (meaning, not execute it) ? Or do you want to also execute it ? If you need to execute it, this gonna be a big problem because you need to compile the code first (you can't execute code on the fly).
|
|
|
|
|
Thanks for your reply.
My C++ code is nothing but a dynamic library which will take conditional(if..else) string(text) and will convert it(to C++ code) and execute it on fly.
Thanks & Regards
Vishrant Shah
|
|
|
|
|
Vishrant Shah wrote: My C++ code is nothing
Vishrant Shah wrote: will convert it(to C++ code) and execute it on fly.
Humm... you really believe that this is "nothing" ? What you are trying to do is a daunting task, because C++ is not a script language. Maybe you could have a look at a scripting language (like Python).
You understand that "executing" C++ code requires first to compile the code ? So, how will you do that at runtime ?
|
|
|
|
|
Cedric, could you please suggest a way to accomplish this ?.
Thanks & Regards
Vishrant Shah
|
|
|
|
|
Can't you simply replace C++ by a scripting language like Python (as I suggest in my previous reply) ?
And why do you need a conversion ? What are you trying to achieve in fact ? Don't reply with what you said in your first post: try to explain the high-level design that brought you to this akward "solution".
|
|
|
|
|
We are doing Financial derivative pricing in C++ using Monte Carlo model. We have a Monte Carlo code which spits out the price of F'derivatives depending upon the payoff formula e.g. max(S-K), (S^2-K^2) ... So, we don't know what payoff formula will be fed in at the runtime. The formula will be specified by a trader/pricer through a VB front-end, which we need to interpret in C++ code, and use it in the Monte Carlo simulation program.
Thanks & Regards
Vishrant Shah
|
|
|
|
|
Vishrant Shah wrote: The formula will be specified by a trader/pricer through a VB front-end, which we need to interpret in C++ code, and use it in the Monte Carlo simulation program.
So the problem has really nothing to do with either C++ or VB. All you are trying to do is interpret some formula entered as text and execute it in real time. This requires some form of parser that will split your string into its constituent tokens and either convert into some format as specified by the simulator, or compute a value via the rules of mathematics. I think you may find many examples, through Google, of simple calculator programs, which you could adapt to your needs.
|
|
|
|
|
You may host the Windows Script Control (download here [^]) in your application.
Since it is an Active X component, its usage (here some examples [^], unfortunately addressing only VB6 applications) maybe a bit complex if you're not experinced in COM programming.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
It's a daunting task: good luck!
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hello all
Though its linux problem I thought I will give a try to my age old forum as the problem seems to be typical memory management ...ok here I go ..
We have a class which has members listed as below in the declaration
class SOAP_CMAC MyUserProfile
{
public:
std::string name;
std::string name2;
std::string firstName;
public:
LONG64 pwdStatus;
std::string setType;
public:
class NotifyOptions *mNotifyOptions;
LONG64 USCOREtype;
std::string USCOREmacAddress;
std::string USCOREipAddress;
public:
MyUserProfile() { }
virtual ~MyUserProfile() { }
};
In the run time after object for MyUserProfile is created , reference to std::strings USCOREmacAddress and USCOREipAddress are crashing due to segmentation fault!
The lines which crash due to segmentation fault are doing an assign operation
USCOREmacAddress.assign(“char string”);
But reference to std::strings name , name2 , firstName and settype do not crash .
Upon observation I found that the line class NotifyOptions *mNotifyOptions is in between the two sections . So I moved the line class NotifyOptions *mNotifyOptions ; to the end of the class declaration . This made the reference to name , name2 , firstName , settype also to crash !!! . It seems this object mNotifyOptions which will be created at run time is somehow the reason for the crash happening on std::string objects ….But I am at wits end to know what it is and how to solve it …
The point is : we migrated from gcc library 2.4. to 2.6 . And after this this problem surfaced without any modifications in the code present in both situations ….
Any help guys on this problem ?
with warm regards
redindian
|
|
|
|
|
If you are not getting any additional warning messages from the compiler with 2.6, then I would check to make sure that all modules were being compiled with the new 2.6 library. Delete all the object modules first if you have to.
|
|
|
|
|
class NotifyOptions *mNotifyOptions;
this is only a pointer, which got to get assigned to an object to work with. As
mNotifyOptions = new NotifyOptions();
in such strange cases you should watch the memory for changes
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
Hi Hans
Could you plesae elaborate your point ?
I understand the memory will be allocated to the pointer of the class object at runtime .
But why and how should it affect the adjacent std::strings ? Also the point I am wondering is that the memory of std::string comes from stack while that of mNotifyOptions is from heap .
regards
redindian
|
|
|
|
|
you got to code it somewhere in your code!!!
mNotifyOptions = new NotifyOptions();
Did you?
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
I would do a search and see if the implementation of malloc was modified between gcc library 2.4 to 2.6. My guess is that if the implementation of malloc changed, memory could be allocated differently using 2.6 over 2.4. You may have already had a memory bug previously using 2.4 but it did not manifest itself until the memory was allocated in some different way using the new library.
Apparently somewhere code is overwriting memory in your class corrupting the private contents of the strings or corrupting the internal datastructures of malloc itself. You need to watch the memory locations for the strings to narrow down when the contents of those strings become corrupted.
One clarification ... do the seg faults happen only when setting the string value or anytime you use the contents of the string ?
|
|
|
|