Skip to content

feat: expose various low level memory management menthods #3895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

adriangb
Copy link

I'm diagnosing memory usage in an application, I think these would be useful to have.

SQLite's highwater marks can be 0 when no tracking has occurred yet,
even if current values are non-zero. Update test assertions to handle
this expected behavior correctly.
///
/// See: https://www.sqlite.org/c3ref/hard_heap_limit64.html
pub fn soft_heap_limit(&mut self, limit: i64) -> i64 {
unsafe { sqlite3_soft_heap_limit64(limit) }
Copy link
Collaborator

@abonander abonander Jun 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The very first line of the linked documentation says:

These interfaces impose limits on the amount of heap memory that will be by all database connections within a single process.

So saying it sets it for the current thread, or having it as a method on the connection. is very misleading.

It should be a free function, or perhaps an associated method of the Sqlite type. Probably a free function.

Passing a negative number just gets the heap limit and doesn't set it, which also needs to be documented.

A more Rust-y API would be something like limit: Option<NonZeroU64>, returning an error if it's greater than i64::MAX (or using a wrapper type with fallible constructors), and providing a separate getter function, but I don't know if we need to go that far. I'd kind of like to sleep on it, though.

///
/// Returns the number of bytes of memory released.
///
/// See: https://www.sqlite.org/c3ref/release_memory.html
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This links to the wrong page. It should be: https://www.sqlite.org/c3ref/db_release_memory.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants