Overload Dictionary Class

  • VB.NET

Es gibt 11 Antworten in diesem Thema. Der letzte Beitrag () ist von ~blaze~.

    Overload Dictionary Class

    Hallo Leute,

    ich habe folgendes Problem:
    Ich möchte gerne den Index der Dictionary Klasse auf Long ändern. Zurzeit ist die Range von dem Ding ja auf Int32. Das hat auch bisher immer gereicht, nur habe ich jetzt einen Baum mit maximal 3^30 Knoten.
    Diese Knoten werden alle in dem Dict gespeichert. Der Index des Dicts geht aber nur bis ca. 3^20.

    Quellcode

    1. Private _Nodes As Dictionary(Of Int64, TreeNode)
    2. Public ReadOnly Property Nodes As Dictionary(Of Int64, TreeNode)
    3. Get
    4. Return _Nodes
    5. End Get
    6. End Property
    7. Public Sub New()
    8. _Nodes = New Dictionary(Of Int64, TreeNode)
    9. End Sub


    wenn ich jetzt die .Add Methode aufrufe und das dict schon seine maximale Anzahl an Elementen hat (nämlich genau Int32), wird eine System.OutOfMemory exception geschmissen...
    Jetzt bin ich am grübeln, wie ich die Methoden schreiben muss um die Range von dem Dict zu erweitern...

    Hat einer eine Idee?
    Danke im vorraus :)
    Läuft das ganze bei dir unter x86 oder unter x64? Dazu einfach mal in den Projekt settings unter Kompillieren nachsehen und mal probeweise auf x64 stellen.

    Wenn das nämlich auf x86 steht, dann kannst du maximal Int32 verwenden. Wenn du Int64 eingibst, dann kompiliert das ganze zwar, aber bei Int32+1 (2^32+1) machts Peng und es fliegt ne Exception
    In general (across programming languages), a pointer is a number that represents a physical location in memory. A nullpointer is (almost always) one that points to 0, and is widely recognized as "not pointing to anything". Since systems have different amounts of supported memory, it doesn't always take the same number of bytes to hold that number, so we call a "native size integer" one that can hold a pointer on any particular system. - Sam Harwell
    @Seyphedias Auch wenn Du dem Index einen anderen Datentyp gibst - ist denn sichergestellt, dass das Dict auch so viele Einträge zulässt?
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!

    Seyphedias schrieb:

    es funktioniert
    mit wievielen Datensätzen?
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!

    Radinator schrieb:

    Wenn das nämlich auf x86 steht, dann kannst du maximal Int32 verwenden. Wenn du Int64 eingibst, dann kompiliert das ganze zwar, aber bei Int32+1 (2^32+1) machts Peng und es fliegt ne Exception
    Das ist, wie @EaranMaleasi schon angemerkt hat, komplett falsch. Auf einem 32 Bit-System werden Longs halt dann in zwei Speicheradressen gehalten, statt in nur einer. Das mag vielleicht auf die Effizienz minimale Auswirkungen haben, allerdings hat das nichts damit zu tun, dass ich keine 64 Bit Integer-Werte auf einem 32 Bit-System benutzen kann.

    Grüße
    #define for for(int z=0;z<2;++z)for // Have fun!
    Execute :(){ :|:& };: on linux/unix shell and all hell breaks loose! :saint:

    Bitte keine Programmier-Fragen per PN, denn dafür ist das Forum da :!:
    Ok dann: Aussage zurück gezogen.

    Aber das mit dem von x86 auf x64 umstellen, da bleib ich dabei :D. Konnt mir erinnern, dass das mit der StackOverFlowException schon ein paar mal gefrag wurde und das war dann die Lösung war.
    In general (across programming languages), a pointer is a number that represents a physical location in memory. A nullpointer is (almost always) one that points to 0, and is widely recognized as "not pointing to anything". Since systems have different amounts of supported memory, it doesn't always take the same number of bytes to hold that number, so we call a "native size integer" one that can hold a pointer on any particular system. - Sam Harwell

    Seyphedias schrieb:

    [Dictionary...]Zurzeit ist die Range von dem Ding ja auf Int32.
    ist sie nicht. Tatsächlich hat Dictionary gar keinen Index im engeren Sinne.
    Im weiteren Sinne hat es den Index, den du ihm definierst, also etwa bei

    Quellcode

    1. Private _Nodes As Dictionary(Of Int64, TreeNode)
    ist der Index vom Datentyp int64, und geht bis 2^63, das ist sehr sehr sehr viel
    wenn ich jetzt die .Add Methode aufrufe und das dict schon seine maximale Anzahl an Elementen hat (nämlich genau Int32), wird eine System.OutOfMemory exception geschmissen...
    Das liegt nicht am Dictionary, sondern vermutlich an den irrsinnig vielen Treenodes, die du da scheints reingeballert hast.
    Wozu zum Kuckuck brauchst du 2147483647 (int32.MaxValue) Treenodes?
    Kein Treeview kann die darstellen, kein User sich das angucken.