|
|
There may be, depending on the processor and number of columns and size of elements. Some processors give fast access to separate bytes of a register (or in the first place form a larger register by adjoining several smaller registers), then perhaps you can form an address almost for free by creating y in the low byte and x in the high byte of the address (likely with an offset otherwise the matrix has to start at 0). This applies to z80 and 8086 and probably some other old CISC architectures (not modern x86 though - it's still possible but no longer actually fast). On a RISC architecture that sort of trick usually doesn't exist. It also typically wastes a lot of memory (you can use the gaps of course but they're fragmented).
|
|
|
|
|
Before using such micro-optimisations, I would ensure that we have used all higher-level optimisations, first. For example:
- How are the data received?
Are they stored in memory in order of reception, or does some processing (e.g. address calculation) need to be performed? - How are the data processed?
Is the access pattern sequential? random?
If a single pass through the data is performed, is it possible to store the data (see question 1 above) in the order of processing, and thereby avoid all indexing?
You may be able to think of other optimisations, based on your knowledge of the hardware and the problem.
Ad astra - both ways!
|
|
|
|
|
Can you please suggest me Best Free tool to detect
1. Application Hang issues in C++ code
2. Memory leaks/ access violation
|
|
|
|
|
|
Using Code Gear /RAD studio. Please advise
|
|
|
|
|
I had a memory allocated out side a try block and I am trying to delete in finally?
Should there be any issue with this. I am getting access violation while deleting
char *heap = new char [50];
try
{
......
}
finally(...)
{
delete[] heap;
}
|
|
|
|
|
It should work when not modifying (which includes deleting) the heap pointer inside the try block.
If you are not doing such (just comment the code inside the try block to check it), you should tell us which compiler you are using because finally is not defined by the C++ standard.
|
|
|
|
|
I am using RAD Studio code gear
|
|
|
|
|
So it is the BCC compiler. According to the __finally (C++) - RAD Studio[^] it should be __try and __finally . When omitting the leading underscores the code should not even compile because try requires a catch and __try requires an __except or __finally .
Is it still not working with the correct syntax and an empty __try block?
Then you might ask this in a BCC specific forum like Recent Topics - Forum - Embarcadero Community[^].
|
|
|
|
|
I am getting an error in a windows include winioctl.h
typedef union {
USN_RECORD_COMMON_HEADER Header;
USN_RECORD_V2 V2; <===
USN_RECORD_V3 V3; <===
USN_RECORD_V4 V4; <====
} USN_RECORD_UNION, *PUSN_RECORD_UNION;
for the 3 lines pointed to by the errors the code built find with the windows sdk 8 I migrated the application to windows 10 and am using the windows 10 sdk
Thanks
|
|
|
|
|
ForNow wrote: ...for the 3 lines pointed to by the errors... And that error would be what?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
C2143 syntax error missing ':' before constant the error might make sense if
USN_RECORD_COMMON_HEADER wasn't defined but it is a few lines above
|
|
|
|
|
But are
USN_RECORD_V2
USN_RECORD_V3
USN_RECORD_V4
defined? That's where I'd look, given your original error messages.
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
typedef USN_RECORD_V2 USN_RECORD, *PUSN_RECORD;
typedef struct {
DWORD RecordLength;
WORD MajorVersion;
WORD MinorVersion;
FILE_ID_128 FileReferenceNumber;
FILE_ID_128 ParentFileReferenceNumber;
USN Usn;
LARGE_INTEGER TimeStamp;
DWORD Reason;
DWORD SourceInfo;
DWORD SecurityId;
DWORD FileAttributes;
WORD FileNameLength;
WORD FileNameOffset;
WCHAR FileName[1];
} USN_RECORD_V3, *PUSN_RECORD_V3;
ypedef struct {
USN_RECORD_COMMON_HEADER Header;
FILE_ID_128 FileReferenceNumber;
FILE_ID_128 ParentFileReferenceNumber;
USN Usn;
DWORD Reason;
DWORD SourceInfo;
DWORD RemainingExtents;
WORD NumberOfExtents;
WORD ExtentSize;
USN_RECORD_EXTENT Extents[1];
} USN_RECORD_V4, *PUSN_RECORD_V4;
|
|
|
|
|
ForNow wrote: C2143 syntax error missing ':' before constant the error might make sense if
USN_RECORD_COMMON_HEADER wasn't defined but it is a few lines above
Could you post these "few lines"?
|
|
|
|
|
Here is the definition USN_RECORD_COMMON_HEADER
typedef struct {
DWORD RecordLength;
WORD MajorVersion;
WORD MinorVersion;
} USN_RECORD_COMMON_HEADER, *PUSN_RECORD_COMMON_HEADER;
|
|
|
|
|
Have a look in Winioctl.h to check the definitions of these types. My version compiles them fine on VS2017 and Windows 10.
|
|
|
|
|
Check the typedef s of the three structures that fail for mutual non standard members.
A candidate is the USN member.
Do you have a define directive using the same name anywhere in your project?
If that does not help enable the creation of preprocessor output files. Then you can check what the compiler "sees".
|
|
|
|
|
|
i was going through a article about friend function and then in i came across this code:
#include <iostream>
using namespace std;
class Distance
{
private:
int meter;
public:
Distance(): meter(0) { }
friend int addFive(Distance);
};
int addFive(Distance d)
{
d.meter += 5;
return d.meter;
}
int main()
{
Distance D;
cout<<"Distance: "<< addFive(D);
return 0;
}
in the above code what is
Quote: Distance(): meter(0) { }
and how is a object of class distance is able to access a private member ?Quote: int addFive(Distance d)
{
//accessing private data from non-member function
d.meter += 5;
return d.meter;
}
Thank you.
|
|
|
|
|
|
You should get hold of a good C++ book. Probably the best would be the one written by Bjarne Stroustrup[^]
|
|
|
|
|
Welcome to C++ .
I mean:
- constructors are the very basics of an OOP language (you must be sure to grasp them before even attempting to code).
- accessing an otherwise unaccessible member is the very purpose of the
friend declaration.
|
|
|
|
|
Problem statement: You are given Q queries. Each query consists of a single number N. You can perform any of the 2 operations on in each move:
1: If we take 2 integers a and b where N=aXb(a!=1,b!=1) then we can change N=max(a,b).
2: Decrease the value of N by 1. Determine the minimum number of moves required to reduce the value of N to 0
Input Format
The first line contains the integer Q.
The next Q lines each contain an integer,N .
Output Format
Output Q lines. Each line containing the minimum number of moves required to reduce the value of N to 0.
Sample Input
2
3
4
Sample Output
3
3
Explanation
For test case 1, We only have one option that gives the minimum number of moves. Follow 3->2 -> 1->0 .
Hence, 3 moves.
For the case 2, we can either go 4->3 ->2 ->1 ->0 or4 -> 2-> 1->0 . The 2nd option is more optimal. Hence, 3 moves.
My algo:
if a number is N then
I do looping until sqrt(N) to find if it is a prime or not.
if it is a prime number then N=N-1
if it not a prime number,one of the largest factor(say a) is <=sqrt(N) then other will be b=N/a now b>a then put N=b;
increment count(pass by value).
then next iteration for N ,until it is greater than 1.
return count.
algorithms works fine with small value but predicts less optimal solution for large values.why?
|
|
|
|