dedicated thread for writing logs and text data/sql Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
MagickPanda
Experienced Solver
Experienced Solver
Posts: 81
Joined: Wed Oct 19, 2016 1:41 pm

dedicated thread for writing logs and text data/sql

Post by MagickPanda »

Hi again, I am planning to write some data I recieve and process in real-time and write the output to ini or sqlite database. So I want to know if there is a wx in-built function to make a I/O queue for asynchronized local file write function, the idea is like this:

1. Process data and make a struct in memory
2. Post the data struct to a dedicated thread with a I/O queue
3. dedicated I/O thread writes the file every [some interval] or priority-based

Thanks again.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: dedicated thread for writing logs and text data/sql

Post by doublemax »

In the default configuration SQLite is thread-safe, so you wouldn't need to do anything. Just write into it from any thread.
https://sqlite.org/threadsafe.html

If you want a dedicated thread for writing, use wxMessageQueue.
http://docs.wxwidgets.org/trunk/classwx ... _01_4.html
Use the source, Luke!
MagickPanda
Experienced Solver
Experienced Solver
Posts: 81
Joined: Wed Oct 19, 2016 1:41 pm

Re: dedicated thread for writing logs and text data/sql

Post by MagickPanda »

doublemax wrote:In the default configuration SQLite is thread-safe, so you wouldn't need to do anything. Just write into it from any thread.
https://sqlite.org/threadsafe.html

If you want a dedicated thread for writing, use wxMessageQueue.
http://docs.wxwidgets.org/trunk/classwx ... _01_4.html
Thanks doublemax.
Hmm is wxSqlite easier to implement than the vanilla stand-alone sqlite?
I remember using sqlite ages ago and it's pretty tricky to get it to work smoothly back then.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: dedicated thread for writing logs and text data/sql

Post by doublemax »

Hmm is wxSqlite easier to implement than the vanilla stand-alone sqlite?
I think yes. First of all it's a C++ wrapper which does all the initialization, memory management etc for you. Also when dealing with wxString, it handles the conversion to/from UTF8 for you.
Use the source, Luke!
MagickPanda
Experienced Solver
Experienced Solver
Posts: 81
Joined: Wed Oct 19, 2016 1:41 pm

Re: dedicated thread for writing logs and text data/sql

Post by MagickPanda »

doublemax wrote:
Hmm is wxSqlite easier to implement than the vanilla stand-alone sqlite?
I think yes. First of all it's a C++ wrapper which does all the initialization, memory management etc for you. Also when dealing with wxString, it handles the conversion to/from UTF8 for you.
Thanks, I will give it a shot some time.
Post Reply