|
By "inverted" do you mean you want to print your list in reverse order?
E.g.
input: 1 2 3 4 5
output: 5 4 3 2 1
"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
|
|
|
|
|
Message Closed
modified 15-May-23 19:06pm.
|
|
|
|
|
If you're having problems understanding that, then you really do need to take a step back, find a good resource for learning C++ and work your way through it. This is simple, basic C++ stuff that you should be able to grok, almost without thinking about it. Using more basic types
class C {
public:
int n;
C() { n = 0; } };
C c; C *pc; C *pc2 = new C();
But these days you really should be using smart pointers instead of new/delete. See the documentation for std::shared_ptr and std::unique_ptr here: [Dynamic memory management - cppreference.com](https://en.cppreference.com/w/cpp/memory)
Keep Calm and Carry On
|
|
|
|
|
Message Closed
modified 15-May-23 19:06pm.
|
|
|
|
|
Every C++ class has a constructor that gets called when the object is created. So if we have
class C {
public:
int n;
C() { n = -1; }
}
int main()
{
C c; std::cout << c.n << '\n'; }
In the class C given above, if you do not give a default constructor, then the compiler will provide one, but it will not initialize the value of C.n
class C {
public:
int n;
};
int main()
{
C c; std::cout << c.n << '\n'; }
Presumably class QBluetoothLocalDevice provides a default constructor that fills in reasonable default values for its members. If some of those members use system resources (e.g. open file handles, memory, etc), then there is also a destructor that gets called when the object goes out of scope to release the resources (e.g close open files, release memory, etc).
Keep Calm and Carry On
|
|
|
|
|
Member 14968771 wrote: Do I have to look thru the QBluetoothLocalDevice class documentation to find which method makes the "test" to contain all the hardware info? Yes, as you would need to do with any class that you are using. And here it all is: QBluetoothLocalDevice Class | Qt Bluetooth 6.4.2[^].
|
|
|
|
|
The first one creates an instance on the stack. It will be destroyed when it goes out of scope.
The second one creates an instance in heap memory*. It will not be automatically destroyed and you should call delete to destroy it.
*Unless new has been overridden to do something unusual.
|
|
|
|
|
1. Create an object on the stack
QBluetoothLocalDevice localDevices;
This reserves all the memory space required for a QBluetoothLocalDevice object on the local stack. It then calls the constructor of the class to initialise any parts of that memory as specified in the class (see answers by @k5054). The variable localDevices holds the address of the object (even though it does not appear to be a pointer).
2. Create an object on the dynamic heap, and return a pointer to it.
QBluetoothLocalDevice *localDevices_new = new QBluetoothLocalDevice();
In this case the memory is requested from the heap, the constructor called to initialise it, and its address returned and saved in the pointer localDevices_new .
The end result is much the same in both cases, apart from the location and lifetime of the two objects. In case 1 the object only exists within the function where it is created; it is automatically destroyed when the function ends. In case 2 the object exists until it is destroyed by the delete statement, or the program terminates.
But as suggested elswhere, this is basic C++, which you should have learned and understood long before you charged down this rabbit hole that you currently find yourself in.
|
|
|
|
|
Member 14968771 wrote: This is a test
in few words of plain English ,
Which suggests homework.
But the answer is no.
The question cannot be answered in "plain english" because it require concepts that only exist in programming. So as the other answers suggest one would need to understand what a 'local variable' is and what a 'heap' is for any answer to make sense.
|
|
|
|
|
It's not homework. This member is struggling with basic concepts in C++.
|
|
|
|
|
Please follow up if the explanations helped.
Charlie Gilley
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
Has never been more appropriate.
|
|
|
|
|
Message Closed
modified 15-May-23 19:06pm.
|
|
|
|
|
oh well, suit yourself.
Charlie Gilley
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
Has never been more appropriate.
|
|
|
|
|
I've tried e.g. QueryThreadCycleTime as follows:
#include <windows.h>
#include <iostream>
int main()
{
for (int i = 0; i < 10; ++i)
{
uint64_t n1 = 0, n2 = 0;
BOOL ok1 = QueryThreadCycleTime(GetCurrentThread(), &n1);
BOOL ok2 = QueryThreadCycleTime(GetCurrentThread(), &n2);
if (ok1 && ok2)
std::cout << n2 - n1 << "\n";
else
std::cout << "n/a\n";
}
}
Typical results are:
1036
1114
1734
748
706
670
652
716
652
666
The numbers vary widely - ok, maybe these are expensive calls - but what is the point then?
If I replace the thread cycles with process cycles, numbers get even weirder:
BOOL ok1 = QueryProcessCycleTime(GetCurrentProcess(), &n1);
BOOL ok2 = QueryProcessCycleTime(GetCurrentProcess(), &n2);
With typical results:
39666
39520
304964
145932
47486
287156
191528
208652
196176
288642
This blog post[^] suggests that it should be no worse than QueryPerformanceCounter , but that's not what I'm seeing.
Anyone with insights?
|
|
|
|
|
The number of CPU clock cycles used by the threads of the process. This value includes cycles spent in both user mode and kernel mode. . So it just shows which threads are consuming what. That may allow you to tune your application if it is largely compute bound.
|
|
|
|
|
Your code on my machine:
2716
2793
2768
2617
2977
2708
2686
2795
2731
2651
well, not perfect, but... Let's try another time:
2703
2891
52734
2611
2623
2613
2611
2609
2608
2592
Absolute rubbish laddie!
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
CPallini wrote: Absolute rubbish laddie! I always suspected you were Scottish and not Italian.
|
|
|
|
|
I am... Pink[^]!
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
peterchen wrote: This blog post[^] suggests that it should be no worse than QueryPerformanceCounter, but that's not what I'm seeing.
Anyone with insights?
My translation of what you are asking:
peterchen should have asked:
QueryProcessCycleTime uses the RDTSC instruction. QueryPerformanceCounter historically also used the RDTSC instruction. Why aren't they giving similar outputs?
As you probably already know the TSC is superceeded by the HPET. There are a dozen reasons why RDTSC provides inaccurate results. The Meltdown/Spectre mitigations were probably the nail in the coffin so to speak.
The answer to your question is that QueryPerformanceCounter uses the HPET/APIC clock and QueryProcessCycleTime is still using the old rdtsc instruction.
It's apparently a huge mess, @HaroldAptroot says sometimes QueryPerformanceCounter uses HPET and sometimes it doesn't depending on whether or not the TSC is invariant.
modified 24-Jan-23 15:14pm.
|
|
|
|
|
Randor wrote: As you probably already know the TSC is superceeded by the HPET. Not actually true though, QPC is based on HPET only when necessary, which is basically if you have a CPU that does not have Invariant TSC (and you don't, unless your CPU is from the mid 2000's). QPC is based on the TSC on every reasonable computer.
|
|
|
|
|
Hmmm,
Do you know where I can find a list of processors with an invariant TSC? I see that cpuid has 80000007H to indicate support but where can I find a list of processors that support it?
|
|
|
|
|
Unfortunately I don't know of such a list and I couldn't find one either. There are lists of CPUID dumps.. not very convenient
|
|
|
|
|
Message Closed
modified 15-May-23 19:06pm.
|
|
|
|
|
The fact that C/C++ is a staticly-typed language has nothing to do with static member functions. In turn these have very little to do with static functions in general. They are just 3 different uses for the same word.
Member 14968771 wrote: If I have a C+_+ class and the function is defined as "static" - what is so different from function which is NOT defined as NOT static ?
Regular member functions have one extra hidden parameter, the "this" pointer, that points to the object on which they are called. Static member functions don't have this hidden parameter and are very much like any regular function except for some scoping rules.
"Static", like "object" and "module" are a very abused words in programming.
Mircea
|
|
|
|
|
Member 14968771 wrote: If I have a C+_+ class and the function is defined as "static" - what is so different from function which is NOT defined as NOT static ? A non-static member function is always called via an object reference. That is any call of the form:
obj.SomeMethod();
has access to all the properties of that particular instance.
But for a static method called thus:
ClassName::StaticMethod();
has no such access, and can only access static members of the class.
But I am not sure that that was your question.
Maybe some C++ learning is in order.
ps, please do not SHOUT in your messages, it is unnecessary and rude.
|
|
|
|