-
Notifications
You must be signed in to change notification settings - Fork 13
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
Add n_free_blocks()
option
#17
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your update.
As I commented, making FREE_BLOCKS
smaller does not necessarily mean that the memory usage will be smaller.
However, a large extras
should not be allocated in stack memory, and I agree with the modification.
Co-authored-by: Shunsuke Kanda <shnsk.knd@gmail.com>
I am using a tiny machine that has just a few amount of the memory. In this machine, This is an example. In this environment, #![feature(alloc_error_handler)]
#![no_main]
#![no_std]
use panic_halt as _;
use core::alloc::Layout;
use alloc_cortex_m::CortexMHeap;
use cortex_m_rt::entry;
use cortex_m_semihosting::{hprintln, debug};
#[global_allocator]
static ALLOCATOR: CortexMHeap = CortexMHeap::empty();
const HEAP_SIZE: usize = 40 * 1024; // 40 KiB
#[entry]
fn main() -> ! {
unsafe { ALLOCATOR.init(cortex_m_rt::heap_start() as usize, HEAP_SIZE) }
let patterns = &["this", "is", "a", "test"];
let pma = daachorse::DoubleArrayAhoCorasickBuilder::new().num_free_blocks(16).build(patterns);
if pma.is_ok() {
hprintln!("OK!").unwrap();
} else {
hprintln!("ERROR!").unwrap();
}
debug::exit(debug::EXIT_SUCCESS);
loop {}
}
#[alloc_error_handler]
fn alloc_error(_layout: Layout) -> ! {
hprintln!("<<< allocation error >>>").unwrap();
loop {}
}
|
This branch removes the following constants:
INIT_CAPACITY
:states
is initialized bywith_capacity()
with this value, but it is often reallocated for a large automaton. On the other hand, this capacity is too large for small devices.FREE_BLOCKS
andFREE_STATES
: Some small devices do not have enough memory, so I added an option to change these parameters.