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, size_t length)
 Returns a pointer to a data segment. 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

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2010-2024 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
2.4.4

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 41 of file net_mem.c.

◆ TRACE_LEVEL

#define TRACE_LEVEL   MEM_TRACE_LEVEL

Definition at line 32 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 100 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 166 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 207 of file net_mem.c.

◆ memPoolInit()

error_t memPoolInit ( void  )

Memory pool initialization.

Returns
Error code

Definition at line 70 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 243 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 604 of file net_mem.c.

◆ netBufferAt()

void* netBufferAt ( const NetBuffer buffer,
size_t  offset,
size_t  length 
)

Returns a pointer to a data segment.

Parameters
[in]bufferPointer to a multi-part buffer
[in]offsetOffset from the beginning of the buffer
[in]lengthLength of the data segment
Returns
Pointer the data segment

Definition at line 418 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 460 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 522 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 282 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 297 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 690 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 322 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 637 of file net_mem.c.

Variable Documentation

◆ memPoolCurrentUsage

uint_t memPoolCurrentUsage

Definition at line 58 of file net_mem.c.

◆ memPoolMaxUsage

uint_t memPoolMaxUsage

Definition at line 60 of file net_mem.c.