net_mem.c File Reference

Memory management. More...

#include "core/net.h"
#include "core/net_mem.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   MEM_TRACE_LEVEL
 
#define MAX_CHUNK_COUNT   (N(MAX(IPV4_MAX_FRAG_DATAGRAM_SIZE, IPV6_MAX_FRAG_DATAGRAM_SIZE)) + 3)
 

Functions

error_t memPoolInit (void)
 Memory pool initialization. More...
 
void * memPoolAlloc (size_t size)
 Allocate a memory block. More...
 
void memPoolFree (void *p)
 Release a memory block. More...
 
void memPoolGetStats (uint_t *currentUsage, uint_t *maxUsage, uint_t *size)
 Get memory pool usage. More...
 
NetBuffernetBufferAlloc (size_t length)
 Allocate a multi-part buffer. More...
 
void netBufferFree (NetBuffer *buffer)
 Dispose a multi-part buffer. More...
 
size_t netBufferGetLength (const NetBuffer *buffer)
 Get the actual length of a multi-part buffer. More...
 
error_t netBufferSetLength (NetBuffer *buffer, size_t length)
 Adjust the length of a multi-part buffer. More...
 
void * netBufferAt (const NetBuffer *buffer, size_t offset)
 Returns a pointer to the data at the specified position. More...
 
error_t netBufferConcat (NetBuffer *dest, const NetBuffer *src, size_t srcOffset, size_t length)
 Concatenate two multi-part buffers. More...
 
error_t netBufferCopy (NetBuffer *dest, size_t destOffset, const NetBuffer *src, size_t srcOffset, size_t length)
 Copy data between multi-part buffers. More...
 
error_t netBufferAppend (NetBuffer *dest, const void *src, size_t length)
 Append data a multi-part buffer. More...
 
size_t netBufferWrite (NetBuffer *dest, size_t destOffset, const void *src, size_t length)
 Write data to a multi-part buffer. More...
 
size_t netBufferRead (void *dest, const NetBuffer *src, size_t srcOffset, size_t length)
 Read data from a multi-part buffer. More...
 

Variables

uint_t memPoolCurrentUsage
 
uint_t memPoolMaxUsage
 

Detailed Description

Memory management.

License

Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneTCP Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
1.9.0

Definition in file net_mem.c.

Macro Definition Documentation

◆ MAX_CHUNK_COUNT

#define MAX_CHUNK_COUNT   (N(MAX(IPV4_MAX_FRAG_DATAGRAM_SIZE, IPV6_MAX_FRAG_DATAGRAM_SIZE)) + 3)

Definition at line 39 of file net_mem.c.

◆ TRACE_LEVEL

#define TRACE_LEVEL   MEM_TRACE_LEVEL

Definition at line 30 of file net_mem.c.

Function Documentation

◆ memPoolAlloc()

void* memPoolAlloc ( size_t  size)

Allocate a memory block.

Parameters
[in]sizeBytes to allocate
Returns
Pointer to the allocated space or NULL if there is insufficient memory available

Definition at line 98 of file net_mem.c.

◆ memPoolFree()

void memPoolFree ( void *  p)

Release a memory block.

Parameters
[in]pPreviously allocated memory block to be freed

Definition at line 164 of file net_mem.c.

◆ memPoolGetStats()

void memPoolGetStats ( uint_t currentUsage,
uint_t maxUsage,
uint_t size 
)

Get memory pool usage.

Parameters
[out]currentUsageNumber of buffers currently allocated
[out]maxUsageMaximum number of buffers that have been allocated so far
[out]sizeTotal number of buffers in the memory pool

Definition at line 205 of file net_mem.c.

◆ memPoolInit()

error_t memPoolInit ( void  )

Memory pool initialization.

Returns
Error code

Definition at line 68 of file net_mem.c.

◆ netBufferAlloc()

NetBuffer* netBufferAlloc ( size_t  length)

Allocate a multi-part buffer.

Parameters
[in]lengthDesired length
Returns
Pointer to the allocated buffer or NULL if there is insufficient memory available

Definition at line 241 of file net_mem.c.

◆ netBufferAppend()

error_t netBufferAppend ( NetBuffer dest,
const void *  src,
size_t  length 
)

Append data a multi-part buffer.

Parameters
[out]destPointer to a multi-part buffer
[in]srcUser buffer containing the data to be appended
[in]lengthNumber of bytes in the user buffer
Returns
Error code

Definition at line 584 of file net_mem.c.

◆ netBufferAt()

void* netBufferAt ( const NetBuffer buffer,
size_t  offset 
)

Returns a pointer to the data at the specified position.

Parameters
[in]bufferPointer to a multi-part buffer
[in]offsetOffset from the beginning of the buffer
Returns
Pointer the data at the specified position

Definition at line 411 of file net_mem.c.

◆ netBufferConcat()

error_t netBufferConcat ( NetBuffer dest,
const NetBuffer src,
size_t  srcOffset,
size_t  length 
)

Concatenate two multi-part buffers.

Parameters
[out]destPointer to the destination buffer
[in]srcPointer to the source buffer
[in]srcOffsetRead offset
[in]lengthNumber of bytes to read from the source buffer
Returns
Error code

Definition at line 440 of file net_mem.c.

◆ netBufferCopy()

error_t netBufferCopy ( NetBuffer dest,
size_t  destOffset,
const NetBuffer src,
size_t  srcOffset,
size_t  length 
)

Copy data between multi-part buffers.

Parameters
[out]destPointer to the destination buffer
[in]destOffsetWrite offset
[in]srcPointer to the source buffer
[in]srcOffsetRead offset
[in]lengthNumber of bytes to be copied
Returns
Error code

Definition at line 502 of file net_mem.c.

◆ netBufferFree()

void netBufferFree ( NetBuffer buffer)

Dispose a multi-part buffer.

Parameters
[in]bufferPointer to the multi-part buffer to be released

Definition at line 280 of file net_mem.c.

◆ netBufferGetLength()

size_t netBufferGetLength ( const NetBuffer buffer)

Get the actual length of a multi-part buffer.

Parameters
[in]bufferPointer to a multi-part buffer
Returns
Actual length in bytes

Definition at line 295 of file net_mem.c.

◆ netBufferRead()

size_t netBufferRead ( void *  dest,
const NetBuffer src,
size_t  srcOffset,
size_t  length 
)

Read data from a multi-part buffer.

Parameters
[out]destPointer to the buffer where to return the data
[in]srcPointer to a multi-part buffer
[in]srcOffsetOffset from the beginning of the multi-part buffer
[in]lengthNumber of bytes to copy
Returns
Actual number of bytes copied

Definition at line 670 of file net_mem.c.

◆ netBufferSetLength()

error_t netBufferSetLength ( NetBuffer buffer,
size_t  length 
)

Adjust the length of a multi-part buffer.

Parameters
[in]bufferPointer to the multi-part buffer whose length is to be changed
[in]lengthDesired length
Returns
Error code

Definition at line 318 of file net_mem.c.

◆ netBufferWrite()

size_t netBufferWrite ( NetBuffer dest,
size_t  destOffset,
const void *  src,
size_t  length 
)

Write data to a multi-part buffer.

Parameters
[out]destPointer to a multi-part buffer
[in]destOffsetOffset from the beginning of the multi-part buffer
[in]srcUser buffer containing the data to be written
[in]lengthNumber of bytes to copy
Returns
Actual number of bytes copied

Definition at line 617 of file net_mem.c.

Variable Documentation

◆ memPoolCurrentUsage

uint_t memPoolCurrentUsage

Definition at line 56 of file net_mem.c.

◆ memPoolMaxUsage

uint_t memPoolMaxUsage

Definition at line 58 of file net_mem.c.