Calloc: Geht, Geht nicht... Speicher ???



  • Hallo,

    irgendwas stimmt nicht mit meinem Calloc, gestern hatte ich Probleme mit dem Calloc Aufruf unter MetroWorks, unterm GCC lief es einwandfrei. Heute compiliere ich das File im MetroWorks und habe keine Probleme dafür hab ich Probleme mit einem dynamisch angelegten Integer Array. Beim ersten Aufruf des Arrays sind alle Werte wie erwünscht, beim zweiten Aufruf (nur printf Ausgabe) stehen auf einmal andere Werte drin ?! 😕 Die Adressen stimmen aber dabei absolut überein ???

    Ist mein Speicher vielleicht irgendwie platt ?

    Winn

    Erster Aufruf
    0 (0x014bc3b0)  4 (0x014bc3b4)  0 (0x014bc3b8)  
    4 (0x014bc3c0)  0 (0x014bc3c4)  0 (0x014bc3c8)  
    0 (0x014bc3d0)  0 (0x014bc3d4)  0 (0x014bc3d8)  
    0 (0x014bc3e0)  0 (0x014bc3e4)  0 (0x014bc3e8)  
    0 (0x014bc3f0)  0 (0x014bc3f4)  0 (0x014bc3f8)  
    0 (0x014bc400)  0 (0x014bc404)  0 (0x014bc408)  
    0 (0x014bc410)  0 (0x014bc414)  0 (0x014bc418)  
    0 (0x014bc420)  0 (0x014bc424)  0 (0x014bc428)  
    0 (0x014bc430)  0 (0x014bc434)  0 (0x014bc438)  
    0 (0x014bc440)  0 (0x014bc444)  0 (0x014bc448)  
    0 (0x014bc450)  0 (0x014bc454)  0 (0x014bc458)  
    0 (0x014bc460)  0 (0x014bc464)  0 (0x014bc468)  
    0 (0x014bc470)  0 (0x014bc474)  0 (0x014bc478)  
    0 (0x014bc480)  0 (0x014bc484)  0 (0x014bc488)  
    0 (0x014bc490)  0 (0x014bc494)  0 (0x014bc498)  
    0 (0x014bc4a0)  0 (0x014bc4a4)  0 (0x014bc4a8)  
    0 (0x014bc4b0)  0 (0x014bc4b4)  0 (0x014bc4b8)  
    0 (0x014bc4c0)  0 (0x014bc4c4)  4 (0x014bc4c8)  
    0 (0x014bc4d0)  4 (0x014bc4d4)  0 (0x014bc4d8)  
    
    Zweiter Aufruf
    1071644672 (0x014bc3b0) 0 (0x014bc3b4)  0 (0x014bc3b8)  
    1071644672 (0x014bc3c0) 0 (0x014bc3c4)  1071644672 (0x014bc3c8) 
    1071644672 (0x014bc3d0) 0 (0x014bc3d4)  0 (0x014bc3d8)  
    1071644672 (0x014bc3e0) 0 (0x014bc3e4)  1071644672 (0x014bc3e8) 
    1071644672 (0x014bc3f0) 0 (0x014bc3f4)  0 (0x014bc3f8)  
    1071644672 (0x014bc400) 0 (0x014bc404)  1071644672 (0x014bc408) 
    0 (0x014bc410)  160 (0x014bc414)    0 (0x014bc418)  
    1071644672 (0x014bc420) 0 (0x014bc424)  0 (0x014bc428)  
    102 (0x014bc430)    21741569 (0x014bc434)   0 (0x014bc438)  
    0 (0x014bc440)  0 (0x014bc444)  0 (0x014bc448)  
    0 (0x014bc450)  0 (0x014bc454)  0 (0x014bc458)  
    0 (0x014bc460)  0 (0x014bc464)  0 (0x014bc468)  
    0 (0x014bc470)  0 (0x014bc474)  0 (0x014bc478)  
    0 (0x014bc480)  0 (0x014bc484)  0 (0x014bc488)  
    0 (0x014bc490)  0 (0x014bc494)  0 (0x014bc498)  
    0 (0x014bc4a0)  0 (0x014bc4a4)  0 (0x014bc4a8)  
    0 (0x014bc4b0)  0 (0x014bc4b4)  0 (0x014bc4b8)  
    0 (0x014bc4c0)  0 (0x014bc4c4)  4 (0x014bc4c8)  
    0 (0x014bc4d0)  4 (0x014bc4d4)  0 (0x014bc4d8)
    


  • oh, das sieht so aus, als ob sich der stack etwas verirrt hat. versuch mal optionen bezüglich des stacks ("SS equals DS"...) bei deinem Compiler zu ändern.

    cu todo



  • Zwei Dinge daran verstehe ich nicht:

    1. Mit Integer sind gar keine Zahlen in der Höhe möglich
    2. Habs nun auch mal mit gcc kompiliert, dabei entstehen die gleichen Zahlenwerte im zweiten Aufruf 😕

    Wie mach ich das mit dem gcc was Du meintest ?

    Winn



  • Original erstellt von Winn:
    **1) Mit Integer sind gar keine Zahlen in der Höhe möglich
    **

    Doch, warum nicht?

    Poste mal bitte etwas Code, ich fühl mich wie bei einer Rateshow ...



  • (StenBound ist mein Problemkind)

    Erster Aufruf:

    double *StenDelta, *StenDStart;
        int *StenBound, *StenBStart;
        StenDelta=(double *)calloc(iSizeOfSpace*iStencilSpace,sizeof(double));
        StenBound=(int *)calloc(iSizeOfSpace*iStencilSpace,sizeof(int));
    
        StenDStart=&StenDelta[0];
        StenBStart=&StenBound[0];
        if ((StenDelta!=NULL) || (StenBound!=NULL))
            {
                alt=0;root=0;
                for(ctr=0;ctr<(iSizeOfDelta);ctr++) 
                    {
                        if (abs(alt-ctr)==iStencilSpace) 
                            {
                                ctr-=iSpaceOrder+(iSpaceOrder-2);
                                alt=ctr;
                                root=ctr;
                                printf("\n");
                            }
                        StenDelta[root*iStencilSpace+ctr]=Delta[ctr];
                        StenBound[root*iStencilSpace+ctr]=Bound[ctr];
                        printf("%i (%p)\t", StenBound[root*iStencilSpace+ctr], &StenBound[root*iStencilSpace+ctr]); // Erster Aufruf
                        // printf("%+f on %d (%2d,%2d)\t", StenDelta[root*iStencilSpace+ctr],StenBound[root*iStencilSpace+ctr], root, ctr);
                    }
                printf("\n\n");
            }
        else
            {
                printf("StenDelta/StenBound began with Nullpointer...\n");
            }
    

    Zweiter Aufruf:

    StenBound=StenBStart;
        alt=0;root=0;
        printf("Ausgabe der Boundary Positionen\n");
        for(ctr=0;ctr<(iSizeOfDelta);ctr++) 
            {
                if (abs(alt-ctr)==iStencilSpace) 
                    {
                        ctr-=iSpaceOrder+(iSpaceOrder-2);
                        alt=ctr;
                        root=ctr;
                        printf("\n");
                    }
                printf("%i (%p)\t", StenBound[root*iStencilSpace+ctr], &StenBound[root*iStencilSpace+ctr]); // Zweiter Aufruf
            }
        printf("\n\n");
    

    [ Dieser Beitrag wurde am 06.06.2003 um 15:46 Uhr von Winn editiert. ]



  • wie groß ist iSizeOfDelta im Vergleich zu iSizeOfSpace? Wundert mich nur ein bißchen, dass du beim allozieren Space und in der for-Schleife Delta verwendest.

    (Davon abgesehen ist die Bedingung zur Abfrage, ob die callocs fehlgeschlagen sind, falsch. Du darfst nur weitermachen, wenn BEIDE erfolgreich waren, dh. !StenBound && !StenDelta. Das tut aber nichts konkret zur Sache.)



  • iSize                   10
    iSpaceOrder     2
    iDomainOffset   1
    iStencilSpace   3
    iSizeOfSpace    19
    iSizeOfDelta    21
    
    Bound[ 0]=+0    Bound[ 1]=+4    Bound[ 2]=+0
    Bound[ 3]=+0    Bound[ 4]=+0    Bound[ 5]=+0
    Bound[ 6]=+0    Bound[ 7]=+0    Bound[ 8]=+0
    Bound[ 9]=+0    Bound[10]=+0    Bound[11]=+0
    Bound[12]=+0    Bound[13]=+0    Bound[14]=+0
    Bound[15]=+0    Bound[16]=+0    Bound[17]=+0
    Bound[18]=+0    Bound[19]=+4    Bound[20]=+0
    
     0 (0x457d0)     4 (0x457d4)     0 (0x457d8)
     4 (0x457e0)     0 (0x457e4)     0 (0x457e8)
     0 (0x457f0)     0 (0x457f4)     0 (0x457f8)
     0 (0x45800)     0 (0x45804)     0 (0x45808)
     0 (0x45810)     0 (0x45814)     0 (0x45818)
     0 (0x45820)     0 (0x45824)     0 (0x45828)
     0 (0x45830)     0 (0x45834)     0 (0x45838)
     0 (0x45840)     0 (0x45844)     0 (0x45848)
     0 (0x45850)     0 (0x45854)     0 (0x45858)
     0 (0x45860)     0 (0x45864)     0 (0x45868)
     0 (0x45870)     0 (0x45874)     0 (0x45878)
     0 (0x45880)     0 (0x45884)     0 (0x45888)
     0 (0x45890)     0 (0x45894)     0 (0x45898)
     0 (0x458a0)     0 (0x458a4)     0 (0x458a8)
     0 (0x458b0)     0 (0x458b4)     0 (0x458b8)
     0 (0x458c0)     0 (0x458c4)     0 (0x458c8)
     0 (0x458d0)     0 (0x458d4)     0 (0x458d8)
     0 (0x458e0)     0 (0x458e4)     4 (0x458e8)
     0 (0x458f0)     4 (0x458f4)     0 (0x458f8)
    
    Ausgabe der Boundary Positionen
    1071644672 (0x457d0)     0 (0x457d4)     0 (0x457d8)
    1071644672 (0x457e0)     0 (0x457e4)    1071644672 (0x457e8)
    1071644672 (0x457f0)     0 (0x457f4)     0 (0x457f8)
    1071644672 (0x45800)     0 (0x45804)    1071644672 (0x45808)
    1071644672 (0x45810)     0 (0x45814)     0 (0x45818)
    1071644672 (0x45820)     0 (0x45824)    1071644672 (0x45828)
     0 (0x45830)     0 (0x45834)     0 (0x45838)
    1071644672 (0x45840)     0 (0x45844)     0 (0x45848)
     0 (0x45850)     6 (0x45854)     0 (0x45858)
     0 (0x45860)     0 (0x45864)     0 (0x45868)
     0 (0x45870)     0 (0x45874)     0 (0x45878)
     0 (0x45880)     0 (0x45884)     0 (0x45888)
     0 (0x45890)     0 (0x45894)     0 (0x45898)
     0 (0x458a0)     0 (0x458a4)     0 (0x458a8)
     0 (0x458b0)     0 (0x458b4)     0 (0x458b8)
     0 (0x458c0)     0 (0x458c4)     0 (0x458c8)
     0 (0x458d0)     0 (0x458d4)     0 (0x458d8)
     0 (0x458e0)     0 (0x458e4)     4 (0x458e8)
     0 (0x458f0)     4 (0x458f4)     0 (0x458f8)
    


  • Folgende Bewandnis hat das Programm,

    ich ermittel die Abstände zwischen zwei Werten, das sind meine Delta's. Die Bound's sind bestimmte Bedingungen die Auswirkung auf die kommende Verarbeitung haben. D.h. die Bound's und Delta's haben eine reale Länge von iSizeOfSpace, sind also gleich lang. Nun brauch ich je nach iSpaceOrder aber etwas mehr Platz und verlänger mir mein Stück zu iSizeOfDelta. Für die Weiterverabeitung brauch ich nun z.B. drei von den Delta's und drei von den Bound's die ich mir in eine separate Liste abspeicher >> StenDelta und StenBound << Dabei sind iDomainOffset soviele Werte zu übernehmen pro >> Stencil (noch nicht soweit) << Dieser Stencil mit der Länge 3 paßt genau iSizeOfSpace mal in iSizeOfDelta hinein...

    Winn



  • Hab den Fehler !! Danke fürs durchlesen 🙂


Anmelden zum Antworten