Auf https://www.buha.info/board/showthread.php?p=401794#post401794 gibt es meine nächste Challenge für die DugJC von BuHa (Die übers ganze Jahr Challenge).
Viel Spass :)
Auf https://www.buha.info/board/showthread.php?p=401794#post401794 gibt es meine nächste Challenge für die DugJC von BuHa (Die übers ganze Jahr Challenge).
Viel Spass :)
So, nun habe ich in Qt ein Programm geschrieben, mit dem ich alle 8 Servos ueber USB/Serielle fernsteuern kann.
Momentan sieht der Datenhandschuh Aktor so aus. Da fehlt nur etwas Fantasie :D
Hab die Tage mein altes Primzahl Projekt wieder ausgegraben. Der nächste Schritt war, die Daten mal mit der Fouriertransforamtion genauer under die Lupe zu nehmen. Um mit der Fouriertransformation etwas vertrauter zu werden, habe ich sie auch gleich mal in C++ implementiert. War auch garnicht so schwer. Zwei Schleifen und komplexe Multiplikationen.
Da der g++ eine Klasse für komplexe Zahlen anbietet, war auch das nicht so schwer. Nur das interpretieren der fouriertransformatieren Daten war nicht so einfach.
In den animierten Bilder unten sieht man das Ergebnis. Die Daten sind in rot dargestellt. Und in grün die Fourierreihe wie sie sich langsam den Daten anpasst. Es wurden aber nur Frequenzen mit einer relativ hohen Amplitute verwendet.
Hier ein vergrösserter Ausschnitt.
Mal sehen was die Tage noch so an Erkenntnisse bringen. Vllt. zeigen sich in größeren Datensätze irgendwelche periodischen Muster.
Eine statische Variable liegt im Heap, statt auf dem Stack. Das erklärt auch, warum das Programm meines Chefs funktionierte, nachdem er vorsorgshalber alle 200 Variablen im Datapool als static deklarierte. Der Stack ist nur einige MB groß (Wie groß genau? Infos suchen!). Fordert man ein entsprechend großes Array an, stürzt das Programm ab.
Gefunden im Buch "Multicore Programmierung" von Intel. Seite 154 ganz Oben.
ISBN 978-3939084-70-9
Im Regelfall sind Variablen, die auf dem Stack deklariert wurden, privat; aber das C/C++ Schlüsselwirt static sorgt dafür, dass die Variable auf dem globalen Heap abgelegt werden und so für alle OpenMP-Schleifen sichbar sind
Noch mehr Infos hab ich hier gefundn http://stackoverflow.com/questions/408670/stack-static-and-heap-in-c
Summary of what static, heap, and stack memory are:
A static variable is basically a global variable, even if you cannot access it globally. Usually there is an address for it that is in the executable itself. There is only one copy for the entire program. No matter how many times you go into a function call (or class) (and in how many threads!) the variable is referring to the same memory location. The heap is a bunch of memory that can be used dynamically. If you want 4kb for an object then the dynamic allocator will look through its list of free space in the heap, pick out a 4kb chunk, and give it to you. Generally, the dynamic memory allocator (malloc, new, et c.) starts at the end of memory and works backwards. Explaining how a stack grows and shrinks is a bit outside the scope of this answer, but suffice to say you always add and remove from the end only. Stacks usually start high and grow down to lower addresses. You run out of memory when the stack meets the dynamic allocator somewhere in the middle (but refer to physical versus virtual memory and fragmentation). Multiple threads will require multiple stacks (the process generally reserves a minimum size for the stack). When you would want to use each one:
Statics/globals are useful for memory that you know you will always need and you know that you don't ever want to deallocate. (By the way, embedded environments may be thought of as having only static memory... the stack and heap are part of a known address space shared by a third memory type: the program code. Programs will often do dynamic allocation out of their static memory when they need things like linked lists. But regardless, the static memory itself (the buffer) is not itself "allocated", but rather other objects are allocated out of the memory held by the buffer for this purpose. You can do this in non-embedded as well, and console games will frequently eschew the built in dynamic memory mechanisms in favor of tightly controlling the allocation process by using buffers of preset sizes for all allocations.) Stack variables are useful for when you know that as long as the function is in scope (on the stack somewhere), you will want the variables to remain. Stacks are nice for variables that you need for the code where they are located, but which isn't needed outside that code. They are also really nice for when you are accessing a resource, like a file, and want the resource to automatically go away when you leave that code. Heap allocations (dynamically allocated memory) is useful when you want to be more flexible than the above. Frequently, a function gets called to respond to an event (the user clicks the "create box" button). The proper response may require allocating a new object (a new Box object) that should stick around long after the function is exited, so it can't be on the stack. But you don't know how many boxes you would want at the start of the program, so it can't be a static.
int main()
{
double a[ ] = { 8.765776478827897e+228, 2.767901447961622e-315 };
const char* s = (char*)&a;
std::cout << s; } Output: hello world!
Dank an Paprikachu
Powered by WordPress