Implement APIs for the counter extension

Use `size_t` for memory length.