GithubHelp home page GithubHelp logo

Comments (4)

ebainville avatar ebainville commented on July 17, 2024

Zeroing a block of memory is usually very fast. Requiring the memory to be 0 is changing the API contract.

Most users will actually call the encode function with scratch_buffer=NULL.

Users calling it with non NULL probably want to avoid re-allocating it for multiple calls. In that case, someone has to clear the buffer before each call anyway, and it will be done inside the LZFSE library.

from lzfse.

nemequ avatar nemequ commented on July 17, 2024

Zeroing a block of memory is usually very fast.

True, but calloc is often faster since the OS or libc may have a block of already zeroed memory sitting around. AFAIK it's pretty common for operating systems to keep some blobs of zeroed memory around just waiting for a calloc().

Requiring the memory to be 0 is changing the API contract.

Since the library isn't installed, I'm not sure how much benefit there is to committing to an API/ABI. IMHO it would be better to flesh out issues, then commit to an API/ABI. However, if you want to commit to the API right now I understand.

If that's the case, though, you should probably be installing the header and shared library (and preferably a pkg-config file). Should I put together a PR for that?

Most users will actually call the encode function with scratch_buffer=NULL.

Perhaps I'm missing something, but does the existing code actually work with NULL for the scratch buffer? I don't see any mallocs or callocs in lzfse, except for in lzfse_main.cā€¦ If I pass NULL to lzfse_encode_buffer in the Squash plugin it crashes.

If nothing else, I guess that is a pretty strong indicator that people aren't passing NULL there.

Users calling it with non NULL probably want to avoid re-allocating it for multiple calls. In that case, someone has to clear the buffer before each call anyway, and it will be done inside the LZFSE library.

Maybe, but that can get complicated pretty quickly in a multi-threaded application. You would need a pool of memory, which is basically what malloc/calloc provides (except it's probably better-optimized than whatever some random programmer will come up with).

from lzfse.

ebainville avatar ebainville commented on July 17, 2024

I'd prefer the LZFSE API to match the Compression API we have been shipping in macOS and iOS since last year. It doesn't require the scratch_buffer to be zeroed, and allows NULL.

Actually the lzfse.h header here documents the NULL case as valid, but you are right: there is no code handling this case. I'll need to fix this ASAP.

from lzfse.

nemequ avatar nemequ commented on July 17, 2024

I see you filed #28, so I may as well close this.

from lzfse.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.