C++Guns – RoboBlog blogging the bot

14.12.2010

How do I remove files that start with a dash?

Filed under: Allgemein — Tags: — Thomas @ 19:12

Since the file name begins with a '-' it looks like an option to the command. You need to force it to not look like an option. Put a ./ in front of it. Or give it the full file name path. Or tell the command you are through with options by using the double dash to end all option processing. This is common to most traditional Unix commands.

rm ./-stuff
rm /full/path/-stuff
rm -- -stuff

And the same for other utilities too.

mv ./-stuff differentstuff
mv -- -stuff differentstuff

http://www.gnu.org/software/coreutils/faq/coreutils-faq.html#How-do-I-remove-files-that-start-with-a-dash_003f

Erschien mir nützlich

10.12.2010

C/C++ eine static Variable liegt im Heap

Filed under: Allgemein — Tags: , — Thomas @ 16:12

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.
  • 30.11.2010

    Schon wieder Uptime weg

    Filed under: Allgemein — Thomas @ 18:11

    Wir ziehen um. Deshalb:

    o2@SGIo2:~$ uptime
     18:05:32 up 185 days,  2:44,  1 user,  load average: 0.23, 0.05, 0.02
    SGIo2:/home/o2# shutdown -h now
    
    Broadcast message from root@SGIo2 (pts/0) (Tue Nov 30 18:06:30 2010):
    
    The system is going down for system halt NOW!
    SGIo2:/home/o2# Connection to kater.mypets.ws closed by remote host.
    Connection to kater.mypets.ws closed.
    kater@kater-desktop:~$ uptime
     18:17:44 up 183 days, 10:39,  3 users,  load average: 0.00, 0.00, 0.00
    kater-desktop:/home/kater# shutdown -h now
    
    The system is going down for system halt NOW!s/11) (Tue Nov 30 18:17:53 2010)
    kater-desktop:/home/kater# Connection to 130.83.141.96 closed by remote host.
    Connection to 130.83.141.96 closed.
    

    Garnicht so einfach ein Platz zu finden, an dem man seine Rechner ein Jahr am Stück laufen lassen kann.

    26.11.2010

    Stuff aus alten Zeiten

    Filed under: Allgemein — Thomas @ 12:11

    Gestern beim stöbern bin ich auf einen Sudoku-Löser in Perl gestossen. Laut timestamp ist die Datei von 2006, aber wahrscheinlich noch viel älter. Ich kann mich erinnern, dass die Datei mal nur 3 Zeilen lang war. Aber durch meine Versuche diesen Wurstsalat wieder etwas auseinander zu frickeln sind ein paar Zeilenumbrüche hinzu gekommen. Wahrscheinlich wird das so auch garnicht mehr funktionieren.
    Da ich kein Plan von Perl habe, kann ich auch nichts weiter zu sagen.

    use integer;
    @A=split//,<>;
    sub R{for$i(0..80){next if$A[$i];
    my%t=map{$_/9
     ==$i/9||$_%9==$i%9||$_/27==$i/27&&$_%9/3==$i%9/3?$A[$_]:0=>1}0..80;
     R($A[
     $i]=$_)for grep{!$t{$_}}1..9;
     return$A[$i]=0}die@A}R
    

    25.11.2010

    Mehr ASCII

    Filed under: Allgemein — Thomas @ 23:11

    Hier mal ein ASCII Strich ^^
    Mit GIF Anitmation damit man auch sieht was passsiert

    pfeil

    Und mein crazy Quellcode

    #include < stdio.h >
    #include < math.h >
    #include < stdlib.h >
    #include < unistd.h >
    
    void gotoxy(int x,int y)
    {
      printf("%c[%d;%df",0x1B,y,x);
    }
    
    int main()
    {
      // Start / End Position des Striches
      float x1 = 0, x2 = 0, y1 = 0, y2 = 0;
      // Laufvariable
      int i = 0;
      // Y Wert der Geraden Gleichgung
      int y = 0;
      // Steigung und F(x) Achsenabschnitt
      float m = 0, b = 0;
      // Winkel
      float rad = 0;
    
      while(1)
      {
        system("clear");
        // Neue x/y Positionen berechnen
        // Gerade hat einen Radius von 10 und ist um 25 in X und 15 in Y verschoben
        x1 = cos(rad) * 10 + 25;
        y1 = sin(rad) * 10 + 15;
        x2 = cos(rad+3.1415) * 10 + 25;
        y2 = sin(rad+3.1415) * 10 + 15;
        // um 1/16PI weiter drehen
        rad += 3.1415/16;
        // Steigung berechnen
        m = (y2-y1)/(x2-x1);
        // Achsenabschnitt berechnen
        b = y1-m*x1;
        // komische Schleife.
        // X1 kann groessr als X2 sein, daher lass schleife so lange laufen
        // bis x1 == x2 ist. Erhoehre oder erniedrige i je nachdem ob x1 groesser
        // x2 ist oder umgekehrt
        // Da nur ueber x Iteriert wird, ist bei einem senkrechten Strich nichts
        // zu sehen. Wenn die Hoehe des Striches groesser als die Breite ist,
        // sollte man ueber y Iterieren.
        for(i = (int)x1; i != (int)x2; x1>x2?i--:i++)
        {
          // Gerade Zeichnen
          y = m*i+b;
          gotoxy(i, y);
          printf("#");
        }
        fflush(stdout);
        sleep(1);
      }
    }
    

    C gotoxy Konsole & ASCII Bildschirmschoner

    Filed under: Allgemein — Tags: — Thomas @ 21:11

    Möchte man ohne zusätzliche Libs den Cursor auf der Konsole frei bewegen, langt folgender kleiner Hack den man sich schnell aus dem Internet googelt.

    Und schwubs di wupp war ein kleiner ASCII Bildschirmschoner hingezaubert.

    #include < stdio.h >
    
    void gotoxy(int x,int y)
    {
      printf("%c[%d;%df",0x1B,y,x);
    }
    
    int main()
    {
      int x = 0, y = 0;
      char c = 0;
      system("clear");
    
      while(1)
      {
        x = rand()%50;
        y = rand()%25;
        c = rand()%'z' + ' ';
        gotoxy(x,y);
        printf("%c", c);
        fflush(stdout);
        sleep(1);
      }
    }

    Und so schaut er aus

    a  avD F        !    ` U /v   y'   z    Y y  j 5
     j   >         \            X         t
    S     9                          e o          X
        R x              m    q            P c   E  >
    -        7r .   =,  7          l       1
      r           m      e       c#     x     ]   "
             t  B       W  b          V
          G       l  m V  OO        zd
    &   7        rX@"  >     dJ          3 )
    h    &        H           R    F         3
       !    l   n     6 K m         #     @  u
            h  # |      O               ,    &
    j  J        *   P     r c  E /      $
             S       \     S      ^  j5S%f          c
                             p     z_z l           n
                   R        f       N   ;  7  q    0
         J   i&     H|   ?    *        y  I      s
    a  |     #    Q   5   g\      D   F       e Ho
      f b  ]            
    	

    24.11.2010

    Noch mehr Helicopter

    Filed under: Allgemein — Tags: — Thomas @ 14:11

    Der Heli hat nun einen neuen Heckmotor bekommen. Der ist so stark, dass der Heli sich fast senkrecht dreht wenn man Vollgas gibt. Entsprechend schnell ist das Ding auch gegen die Wand geflogen.
    Scharfe Kurven kann man damit leider nun doch nicht fliegen, da sehr schnell die Blätter des unteren und oberen Rotors aneinander kommen.

    Anbei noch ein Video wie Chef seinen Heli fetzt.
    http://www.dailymotion.com/video/xfrbqd_chef-fetzt-sein-heli_fun

    30.10.2010

    C++ Hello World mal anders

    Filed under: Allgemein — Tags: , — Thomas @ 17:10

    int main()
    {
    double a[ ] = { 8.765776478827897e+228, 2.767901447961622e-315 };
    const char* s = (char*)&a;
    std::cout << s; } Output: hello world!

    Dank an Paprikachu

    mein code

    Filed under: Allgemein — Thomas @ 17:10

    < dot > mein code enthält nur kommentare wenn grad wo n block auskommentiert ist :P

    Was will man da noch sagen ;)

    18.10.2010

    Windows - Nur ein CPU Kern erlaubt

    Filed under: Allgemein — Thomas @ 06:10

    Der Prozessor darf bis zu 2 GHz schnell sein, aber nur einen Kern haben. Die Beschränkung der Festplatte fällt komplett weg. Weiterhin darf das Display nur eine 10,2-Zoll-Diagonale haben und der Hauptspeicher nur 1 GByte fassen.

    http://www.heise.de/mobil/meldung/Windows-7-Netbooks-mit-groesserer-Platte-837573.html

    http://www.heise.de/newsticker/meldung/Netbook-mit-AMD-Prozessor-1109025.html

    < ArtificialMind2 > jo windows 7 starter ist schon witzig
    < ArtificialMind2 > man darf sein hintergrundbild auch nicht verändern

    « Newer PostsOlder Posts »

    Powered by WordPress