AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Stack overflow

Ein Thema von vsilverlord · begonnen am 15. Jun 2008 · letzter Beitrag vom 15. Jun 2008
Antwort Antwort
Benutzerbild von vsilverlord
vsilverlord

Registriert seit: 7. Jan 2008
Ort: Baden Württemberg- Hohenlohekreis
174 Beiträge
 
RAD-Studio 2009 Arc
 
#1

Stack overflow

  Alt 15. Jun 2008, 15:14
Hallihallo, also ich hab hier so ein Problem.
Zuerst hatte ich eine ganz normale eigene procedure, die sah ungefähr so aus.
Delphi-Quellcode:
procedure tform1.Spurzeichnen(image:timage);
var
i,s,x,y:integer;
begin
i:=1;
s:=0;
while i <= Personenanzahl do
begin
  x:=Daten[i].Ort[0].x;
  y:=Daten[i].Ort[0].y;
  image.Canvas.MoveTo(x,y);
  s:=1;
   while s <= Daten[i].Anzahl do
      begin
         x:=Daten[i].Ort[s].x;
         y:=Daten[i].Ort[s].y;
         image.Canvas.LineTo(x,y);
         s:=s+1;
      end;
  i:=i+1;
end
end;
Daten ist vom Typ TOrte und speichert die einzelnen Positionen aller Orte:
Delphi-Quellcode:
TOrte = record
    Ort:array[0..1000]of Tpoint;
    Anzahl: integer; //Anzahl der Schritte
end;
...
var
Form1: TForm1;
Daten:array[0.1000]of TOrte;
Personenanzahl:integer
Das Programm soll Spur der Personen speichern, hat auch wunderbar geklappt.
Jetzt hab ich noch eine eigene Klasse gebaut, die Datengruppe, um das Programm noch etwas zu verallgemeinern:
Delphi-Quellcode:
TDatengruppe = record
      Daten:array[0..1000]of TOrte;
      Personenanzahl: integer;
end;
...
var
Form1: TForm1;
Datengruppe1:Tdatengruppe
somit mussste ich nur noch die Procedure noch verallgemeinern:
Delphi-Quellcode:
procedure tform1.Spurzeichnen(image:timage,Datengruppe:Tdatengruppe);
var
i,s,x,y:integer;
begin
i:=1;
s:=0;
while i <= Datengruppe.Personenanzahl do
begin
  x:=Datengruppe.Daten[i].Ort[0].x;
  y:=Datengruppe.Daten[i].Ort[0].y;
  image.Canvas.MoveTo(x,y);
  s:=1;
   while s <= Datengruppe.Daten[i].Anzahl do
      begin
         x:=Datengruppe.Daten[i].Ort[s].x;
         y:=Datengruppe.Daten[i].Ort[s].y;
         image.Canvas.LineTo(x,y);
         s:=s+1;
      end;
  i:=i+1;
end
end;
Aufrufen der Procedure mit Button:
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
begin
Spurzeichnen(image1,datengruppe1)
end
Jetzt kommt plötzlich ein Stack-overflow, wenn ich diese procedure ausfühern will!! warum??
Ich habe doch eigentlich nichts verändert!
Volker
~beware
Wizards First Rule:
People are stupid; given proper motivation, almost anyone will believe almost anything. Because people are stupid, they will believe a lie because they want to believe it’s true, or because they are afraid it might be true
  Mit Zitat antworten Zitat
Benutzerbild von Bernhard Geyer
Bernhard Geyer

Registriert seit: 13. Aug 2002
17.171 Beiträge
 
Delphi 10.4 Sydney
 
#2

Re: Stack overflow

  Alt 15. Jun 2008, 15:23
Ein Record vom Typ TOrte benötigt: 1001 * 2 * 4 Byte = 8008 Byte
Ein Record vom Typ TDatengruppe benötigt: 8008 Byte * 1001 + 4 Byte = 8016012 Byte.

So wie du diese Records verwendest wird beim Aufruf der Funktion diese ca. 8 MB große Record kopiert (!) und auf dem Stack gelegt. Und im Normalfall ist bei einem Projekt die Stackgröße nicht so hoch (Kann in den Projektoptionen verändert werden).
Windows Vista - Eine neue Erfahrung in Fehlern.
  Mit Zitat antworten Zitat
Benutzerbild von vsilverlord
vsilverlord

Registriert seit: 7. Jan 2008
Ort: Baden Württemberg- Hohenlohekreis
174 Beiträge
 
RAD-Studio 2009 Arc
 
#3

Re: Stack overflow

  Alt 15. Jun 2008, 15:42
Das erschreckt mich jetzt. Wie kann ich das anders programmieren?
Volker
~beware
Wizards First Rule:
People are stupid; given proper motivation, almost anyone will believe almost anything. Because people are stupid, they will believe a lie because they want to believe it’s true, or because they are afraid it might be true
  Mit Zitat antworten Zitat
Benutzerbild von Bernhard Geyer
Bernhard Geyer

Registriert seit: 13. Aug 2002
17.171 Beiträge
 
Delphi 10.4 Sydney
 
#4

Re: Stack overflow

  Alt 15. Jun 2008, 15:45
Zitat von vsilverlord:
Das erschreckt mich jetzt. Wie kann ich das anders programmieren?
Fürs erste ein Const ergänzen umd das kopieren der Daten zu verhindern.

procedure tform1.Spurzeichnen(image:timage, const Datengruppe: Tdatengruppe);
Windows Vista - Eine neue Erfahrung in Fehlern.
  Mit Zitat antworten Zitat
Apollonius

Registriert seit: 16. Apr 2007
2.325 Beiträge
 
Turbo Delphi für Win32
 
#5

Re: Stack overflow

  Alt 15. Jun 2008, 15:56
Und auf Dauer unbedingt dein Design auf dynamische Arrays umstellen.
Wer erweist der Welt einen Dienst und findet ein gutes Synonym für "Pointer"?
"An interface pointer is a pointer to a pointer. This pointer points to an array of pointers, each of which points to an interface function."
  Mit Zitat antworten Zitat
Benutzerbild von vsilverlord
vsilverlord

Registriert seit: 7. Jan 2008
Ort: Baden Württemberg- Hohenlohekreis
174 Beiträge
 
RAD-Studio 2009 Arc
 
#6

Re: Stack overflow

  Alt 15. Jun 2008, 15:56
Vielen Dank! Das funktioniert. ich wusste nicht, dass da das ganze System kopiert wird!
Volker
~beware
Wizards First Rule:
People are stupid; given proper motivation, almost anyone will believe almost anything. Because people are stupid, they will believe a lie because they want to believe it’s true, or because they are afraid it might be true
  Mit Zitat antworten Zitat
Benutzerbild von vsilverlord
vsilverlord

Registriert seit: 7. Jan 2008
Ort: Baden Württemberg- Hohenlohekreis
174 Beiträge
 
RAD-Studio 2009 Arc
 
#7

Re: Stack overflow

  Alt 15. Jun 2008, 15:57
Kannst du mir da bitte für mein Programm ein Beispiel machen?
Volker
~beware
Wizards First Rule:
People are stupid; given proper motivation, almost anyone will believe almost anything. Because people are stupid, they will believe a lie because they want to believe it’s true, or because they are afraid it might be true
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 01:57 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz