AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Programmieren allgemein GNU C++ - wie Speicherfehler abfangen ?
Thema durchsuchen
Ansicht
Themen-Optionen

GNU C++ - wie Speicherfehler abfangen ?

Ein Thema von paule32.jk · begonnen am 13. Aug 2024 · letzter Beitrag vom 19. Aug 2024
 
Kas Ob.

Registriert seit: 3. Sep 2023
455 Beiträge
 
#9

AW: GNU C++ - wie Speicherfehler abfangen ?

  Alt 15. Aug 2024, 08:27
QChar is 2 bytes structure supplied with methods and default constructor, yes there is a constructor but it is more filling with default value which is 0.

Now, look how you declared it, in your code there is no "*", it is local field and in-place, trying to delete it itself will not be possible.

Also see your example posted here against the one in the GitHub
Code:
namespace "qvc" {
class QChar {
private:
    ::QChar* origin_obj;
public:
    QChar();
    ~QChar();
...
};

qvc::QChar::~QChar(void)
{
    #ifdef DEBUG
    std::wcout << L"cpp: QChar: dtor..." << std::endl;
    #endif
    try {
        if (nullptr != origin_obj) {
            std::wcout << L"not null" << std::endl;
            delete origin_obj;
        }
    }
    catch (std::exception &e) {
        std::wcout << L"Exception: ";
        std::wcout << e.what() << std::endl;
    }
}
}
Code:
namespace qvc {

qvc::QChar::QChar(void     ) { origin_obj = new ::QChar( ); }
qvc::QChar::QChar(char    t) { origin_obj = new ::QChar(t); }
qvc::QChar::QChar(uint8_t t) { origin_obj = new ::QChar(t); }
qvc::QChar::QChar(uint16_t t) { origin_obj = new ::QChar(t); }
qvc::QChar::QChar(uint32_t t) { origin_obj = new ::QChar(t); }
qvc::QChar::QChar(wchar_t t) { origin_obj = new ::QChar(t); }
qvc::QChar::QChar(short   t) { origin_obj = new ::QChar(t); }
...

qvc::QChar::~QChar(void)
{
    #ifdef DEBUG
    std::wcout << L"cpp: QChar: dtor..." << std::endl;
    #endif
    try {
        if (nullptr != origin_obj) {
            std::wcout << L"not null" << std::endl;
            delete origin_obj;
        }
    }
    catch (std::exception &e) {
        std::wcout << L"Exception: ";
        std::wcout << e.what() << std::endl;
    }
}
See the difference ?

In all cases, QChar is 2 bytes and this is smaller and lighter than using dynamic one with extra pointer (either 32 or 64 bit, meaning 4 or 8 bytes) with overhead of allocating and deallocating, just slap it where ever you need to use, as static and in place then use it and don't free it, because it does not need to be free.

In other words use it as you use int or LONG .... the only difference is it will have initial value, and comes with methods, that is it.
Kas
  Mit Zitat antworten Zitat
 


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 03:06 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz