Skip to contentSkip to conversation

PPP: Switch ringbuffer.c to g_slice allocator

PATCH In review Patrick Porlan 2 participants 2 messages Mar 16, 2011 – Mar 17, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PPP: Switch ringbuffer.c to g_slice allocator

This should allow for more efficient handling of equally sized buffers, in terms of alignment and recycling.

---
 gatchat/ringbuffer.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
gatchat/ringbuffer.c +4 -4
index 27be3a8..775498c 100644
@@ -51,11 +51,11 @@ struct ring_buffer *ring_buffer_new(unsigned int size)
 	if (real_size > MAX_SIZE)
 		return NULL;
 
-	buffer = g_try_new(struct ring_buffer, 1);
+	buffer = g_slice_new(struct ring_buffer);
 	if (buffer == NULL)
 		return NULL;
 
-	buffer->buffer = g_try_new(unsigned char, real_size);
+	buffer->buffer = g_slice_alloc(real_size);
 	if (buffer->buffer == NULL) {
 		g_free(buffer);
 		return NULL;
@@ -202,6 +202,6 @@ void ring_buffer_free(struct ring_buffer *buf)
 	if (buf == NULL)
 		return;
 
-	g_free(buf->buffer);
-	g_free(buf);
+	g_slice_free1(buf->size, buf->buffer);
+	g_slice_free1(sizeof(struct ring_buffer), buf);
 }
Signature · 1 line
1.7.1
#1 lore raw

Hi Patrick,

Quoted 6 lines · Patrick Porlan

This should allow for more efficient handling of equally sized buffers, in terms of alignment and recycling.

---
 gatchat/ringbuffer.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

Patch has been applied, thanks.

Regards,
-Denis