[ 
https://issues.apache.org/jira/browse/TS-2581?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15276957#comment-15276957
 ] 

ASF GitHub Bot commented on TS-2581:
------------------------------------

Github user jpeach commented on a diff in the pull request:

    https://github.com/apache/trafficserver/pull/622#discussion_r62565756
  
    --- Diff: iocore/eventsystem/IOBuffer.cc ---
    @@ -271,3 +272,74 @@ IOBufferReader::memcpy(const void *ap, int64_t len, 
int64_t offset)
     
       return p;
     }
    +
    +void *
    +ats_malloc_pool(size_t size)
    +{
    +  void *ptr = NULL;
    +  size_t total_required_size = size + sizeof(uint64_t);
    +
    +  if (likely(size > 0)) {
    +    if (unlikely(total_required_size > DEFAULT_MAX_BUFFER_SIZE)) {
    +      // we need to fall back to ats_malloc for large allocations
    +      ptr = ats_malloc(total_required_size);
    +    } else {
    +      int64_t iobuffer_index = iobuffer_size_to_index(total_required_size);
    +      ink_release_assert(iobuffer_index >= 0);
    +
    +      ptr = ioBufAllocator[iobuffer_index].alloc_void();
    +      Debug("allocator_pool",
    +            "Allocating a block from iobuf index %ld (block size %ld), 
requested_size = %ld, alloc size = %ld at location %p",
    +            iobuffer_index, index_to_buffer_size(iobuffer_index), size, 
total_required_size, ptr);
    +    }
    +  } else {
    +    return NULL;
    +  }
    --- End diff --
    
    Well I disagree that consistency is bike shedding :)


> Add / modify APIs to allow easy freelist allocation of iobuffer's from C/C++ 
> plugins
> ------------------------------------------------------------------------------------
>
>                 Key: TS-2581
>                 URL: https://issues.apache.org/jira/browse/TS-2581
>             Project: Traffic Server
>          Issue Type: New Feature
>          Components: TS API
>            Reporter: Leif Hedstrom
>            Assignee: Jason Kenny
>              Labels: api-addition, newbie
>             Fix For: 7.0.0
>
>
> This would allow for efficient allocations in plugins, such that they can do 
> an in-place new() on a chunk of memory (iobuffer). 
> The API / features should make it easy and possible to asks for an iobuffer 
> of at least size <x>. It can return a bigger one, at which point, you'd waste 
> some. But this allows us to reuse / repurpose the existing iobuffer 
> allocation.
> Phil points out that there are existing iobuffer allocation APIs, so maybe 
> something in conjunction with that is appropriate. I would like for this to 
> be easy on the plugin user though, such that it's as simple as "malloc/free" 
> chains.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to