|
wislamOS wrote: wold like to invoke a function created by C# from a c++ code
Can't do that (unless you host .NET in your C++ application and that's where I get lost.)
For all intents and purposes, you can call native C++ from C#, but not the other way around.
|
|
|
|
|
C++/CLI lets you call both ways.
|
|
|
|
|
That's why I said "native"
|
|
|
|
|
|
I have a reader that reads an int
and I have a writer that modifies that int.
In other words I have an int called iVal :
int iVal;
And I have a thread A that constantly reads iVal and another different thread B that, sometimes modifies the value of iVal.
My concern is with problems that may arise when A is reading iVal at the same time B is modifying it.
I used to rely on InterlockedIncrement,etc whenever I have the scenario of two writers for the same variable.
But what if my writer (B) could do more than a simple incrementation and that my readers must read the value as it is just before the writer could modify it or as it is just after it would be modified ?
I'm not sure already that the depicted scenario is unsafe. It data incorrectness could happen and cause the reader to behave in unplanned way. Moreover I seek a simple way without introducing a critical section for iVal variable :
Ie I want to avoid having to wrap the simple iVal into a class and do things like the following :
Class CValue{
private :
CCRITICAL_SECTION cs;
int iVal;
public:
CValue()
{
InitializeCriticalSection(&cs);
}
~CValue()
{
DeleteCriticalSection(&cs);
}
void setValue(int iVal)
{
EnterCriticalSection(&cs);
this->iVal = iVal;
LeaveCriticalSection(&cs);
}
int getValue()
{
int _iVal;
EnterCriticalSection(&cs);
_iVal = iVal;
LeaveCriticalSection(&cs);
return _iVal;
}
}
Thank you..in advance.
Easy Profiler : a compile-time profiler for C++
www.potatosoftware.com
|
|
|
|
|
That will work, though on an x86, simply declaring iVal as volatile would be sufficient since x86 will read or write the int value as an atomic operation IF it's on a DWORD boundary.
(The reason you need other protection in incrementing/decrementing is that incrementing may not be an atomic operation.)
|
|
|
|
|
Which messages should I process to ensure my window cannot be reduced below a certain size?
I'm currently processing the WM_SIZING message which works fine when the user is dragging the edge of the window but it's possible to use explorer to highlight multiple windows on the taskbar and then select the 'Show Windows Stacked' option from the context menu. This currently results in the window size being reduced below it's minium.
|
|
|
|
|
Try WM_GETMINMAXINFO[^].
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
That did the job. Thanks for the suggestion.
|
|
|
|
|
http://en.wikipedia.org/wiki/Harmonic_average[^]
This program calculates Harmonic avarage in my opinion, but as i understand its not exactly corect. If i would need to make this from tousands numbers would this " b=b+1.0000000/a[i]; " be the same value as it should be or its just a bit diferent.
/* 2. Write a program which reads 10 numbers, and computes the harmonic average
*/
#include <iostream>
using namespace std;
int main() {
double a[10];
double b;
b=0;
for(int i=0;i<10;i++){
cin >>a[i];
b=b+1.0000000/a[i];
}
cout <<b/10;
}
|
|
|
|
|
I just started, all my knowlage is just pascal ...
This should work, but it prints Nan instead of "too few numbers" when i enter n=0 or aall a values are negative...
/* 1. Write a program which reads a number, n, and then n numbers of type double, i.e.,
input data are
n x1 x2 x3 : : : xn
The program should write out the average of the positive x-values. If the number of
positive values is less than 1, the text \too few numbers" should be written.
*/
#include <iostream>
using namespace std;
int main() {
int n;
double a[n];
for(int i=0;i<n;i++){
cin >> a[i];
}
double sum;
int kiek;
for(int i=0;i<n;i++) {
if (a[i]>0) {
sum=sum+a[i];
kiek=kiek+1;
}
}
if (kiek<1)
cout << "too few numbers";
else
cout<< sum/kiek;
return 0;
}
|
|
|
|
|
zutautas wrote: int n;
double a[n];
This even compiles? You cannot allocate memory dynamically on the stack (the value n should be a constant and "known").
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Rajesh R Subramanian wrote: You cannot allocate memory dynamically on the stack
Actually, you can. See here[^].
Steve
|
|
|
|
|
I'm sure he knows that. His sentence is bound to the context, i.e. "you cannot allocate memory dynamically on the stack that way"
(I'm one of the 10 Rajesh's monkeys... )
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]
|
|
|
|
|
Yea i have writed
(...
int n;
cin >>n;
double a[n];
...)
earlyer, but didnt saved , now this works fine:
int main() {
int n;
cin >>n;
double a[n];
for(int i=0;i<n;i++){
cin >> a[i];
}
double sum;
int kiek;
kiek=0;
sum=0;
for(int i=0;i<n;i++) {
if (a[i]>0) {
sum=sum+a[i];
kiek=kiek+1;
}
}
if (kiek<1)
cout << "too few numbers";
else
cout<< sum/kiek;
return 0;
}
did i need to enter kiek and sum begining values, and if i leave them with no beginning values they are 0 or 1 ?
|
|
|
|
|
Why didn't you answer Rajesh's question?
How can the following code
zutautas wrote: int n;
cin >>n;
double a[n];
compile?
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]
|
|
|
|
|
its a part from all code...
...
int n;
cin >>n;
double a[n];
...
i dont know how you showing just few lines instead of all text, but i do it this way
|
|
|
|
|
I show few lines that should NOT compile. I wonder why your compiler doesn't complain.
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]
|
|
|
|
|
My comment was in context with what the OP was trying to do there -- I had put the context within parenthesis in my previous post.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Hi everyone i m facing one problem while writing buffer into a file.
Actually i m using Ramanan T's NTFS undelete code for reading MFT table for files in
NTFS file system of a partition.
Undelete a file in NTFS
I m getting junk characters for small headers files of visual studio.Its reading all other formatted files like .doc,.xls or JPEG,.bmp etc properly.Even large sized cpp files also reading properly.i m reading 4kb ie one cluster at a time.
Here is the code where i m getting the junk characters.
class CErrorLog
{
public:
CErrorLog(void);
public:
Í ErrorLog(void);
WCHAR wcErrLogPath[QP_MAX_PATH];
}
I m not able to find out why that junk is coming in between for some files only
Thankx in advance for any help.....
|
|
|
|
|
Hi,
I have not looked at the source code at the link you provided. However I know from experience that small files under 1kb are not stored on a disk cluster on an NTFS disk. On a disk with a 4kb cluster size it would waste 3+ kilobytes. They are instead stored directly in the $MFT FRS segment. Check the source code and see if the author added special code for this sitation.
You should not trust that all source code you find on the internet is written correctly to handle all sitations.
Best Wishes,
-David Delaune
|
|
|
|
|
ya David ur absolutely right that i should not depend completely on the code,but as you had asked that is there is any special provision made in this code to handle Resident files which are stored in $MFT FRS.Yes there is but still same problem is coming.Out of 100 only 2 or 3 files are being getting corrupted.Actually i dont know how to read MFT table through data runs (by using VCN's & LCN's) thats why i m using that code .If u have any idea about reading MFT table please let me know ...........
|
|
|
|
|
I write a COM class in VC++ that is used in a .Net WebService as a refrence.
The COM object has an interface that simulates an IDispatch array to pass arrays of different objects to/from COM object.
I can pass that array to COM object in C# samples correctly, but when i pass it in C# webservice i get exception.
Can enyone help me?
Is there any limitation for WebServices in using COM objects
|
|
|
|
|
Hi all,
please tell me how can i get details of CPU and Memory usage that is used by my application.
please help me for ths.
thanks in advance.
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|
|
"_$h@nky_" wrote: how can i get details of CPU and Memory usage that is used by my application.
See GetProcessTimes()[^]
What memory usage? The working set? If yes, then see GetProcessWorkingSetSize()[^].
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|