Skip to content

Is it a good idea to add max_buffer_reuse? #91

Open

Description

@edo888

local hex_buf = ffi_new(str_type, BUF_MAX_LEN)

Activity

  1. zhuizhuhaomeng commented on Oct 29, 2022

    @zhuizhuhaomeng
    Contributor

    I think it is a good idea.
    but we need a better function name.

  2. edo888 commented on Oct 29, 2022

    @edo888
    Author

    Does this look good?

    local str_type = ffi.typeof("uint8_t[?]")
    
    local counter = 0
    local BUF_MAX_REUSE = 10000
    local BUF_MAX_LEN = 1024
    local hex_buf = ffi_new(str_type, BUF_MAX_LEN)
    function _M.to_hex(s)
        local len = #s
        local buf_len = len * 2
        local buf
        if buf_len <= BUF_MAX_LEN then
            counter = counter + 1
            if counter > BUF_MAX_REUSE then
                hex_buf = ffi_new(str_type, BUF_MAX_LEN)
                counter = 0
            end
    
            buf = hex_buf
        else
            buf = ffi_new(str_type, buf_len)
        end
        C.ngx_hex_dump(buf, s, len)
        return ffi_str(buf, buf_len)
    end
    
  3. zhuizhuhaomeng commented on Nov 2, 2022

    @zhuizhuhaomeng
    Contributor

    I final got what you mean.
    Why do you need the max reuse time ?

  4. edo888 commented on Nov 2, 2022

    @edo888
    Author

    I'm worried about burning out RAM when using to_hex heavily, so I'm asking your opinion about it. Is it a good idea or it should be fine? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions