by rtpg · 4w ago · 0 comments
> I remember back in the day, apps like Miranda IM (and early versions of Trillian) used only digits of RAM, even when you had multiple plugins talking several protocols at the same time
I think what's happening in the second one is that because you're using the native OS toolkits a bunch of stuff is shared, whereas with these "self-contained" "native"-y apps you end up having to load up the whole world and aren't sharing things with everything else
I'd love to be proven wrong but I feel like if you use e.g. Qt you're gonna have to hold onto a bunch of stuff that you wouldn't if you were "just" using OS-native stuff (though maybe that gets shared if you're using the exact same version? Is there something that can be done in this space?)
$ ps -o pid,rss,command -p $(pgrep -f SimpleQtApp)
PID RSS COMMAND
1471929 33052 ./SimpleQtApp
$ ps -o pid,rss,command -p $(pgrep -f SimpleQmlApp)
PID RSS COMMAND
1478335 123260 ./SimpleQmlApp
// Following is the simple Qt app code.
#include <QApplication>
#include <QWidget>
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>
int main(int argc, char argv[]) {
QApplication app(argc, argv);
QWidget window;
window.setWindowTitle("Qt Simple App (CMake)");
window.resize(300, 150);
QLabel *label = new QLabel("Hello, World!", &window);
label->setAlignment(Qt::AlignCenter);
QPushButton *button = new QPushButton("Click Me", &window);
QVBoxLayout *layout = new QVBoxLayout(&window);
layout->addWidget(label);
layout->addWidget(button);
QObject::connect(button, &QPushButton::clicked, [label]() {
label->setText("You clicked the button!");
});
window.show();
return app.exec();
}// Following is the QML app code
#include <QGuiApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[]) {
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:/Main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed, &app, []() { QCoreApplication::exit(-1); }, Qt::QueuedConnection);
engine.load(url);
return app.exec();
}// Main.qml
import QtQuick
import QtQuick.Controls
Window {
width: 320
height: 200
visible: true
title: "Simple QML Application"
Column {
anchors.centerIn: parent
spacing: 20
Label {
id: statusLabel
text: "Hello, QML World!"
font.pointSize: 16
anchors.horizontalCenter: parent.horizontalCenter
}
Button {
text: "Click Me"
anchors.horizontalCenter: parent.horizontalCenter
// Handle click event inline
onClicked: {
statusLabel.text = "You clicked the QML button!"
}
}
}
}