Dont use the python memory pool for the history buffer
It's not optimized for this use case
This commit is contained in:
parent
4ccd2afd78
commit
63e5be6ff0
@ -17,12 +17,12 @@ extern PyTypeObject Line_Type;
|
|||||||
static inline void
|
static inline void
|
||||||
add_segment(HistoryBuf *self) {
|
add_segment(HistoryBuf *self) {
|
||||||
self->num_segments += 1;
|
self->num_segments += 1;
|
||||||
self->segments = PyMem_Realloc(self->segments, sizeof(HistoryBufSegment) * self->num_segments);
|
self->segments = realloc(self->segments, sizeof(HistoryBufSegment) * self->num_segments);
|
||||||
if (self->segments == NULL) fatal("Out of memory allocating new history buffer segment");
|
if (self->segments == NULL) fatal("Out of memory allocating new history buffer segment");
|
||||||
HistoryBufSegment *s = self->segments + self->num_segments - 1;
|
HistoryBufSegment *s = self->segments + self->num_segments - 1;
|
||||||
s->cpu_cells = PyMem_Calloc(self->xnum * SEGMENT_SIZE, sizeof(CPUCell));
|
s->cpu_cells = calloc(self->xnum * SEGMENT_SIZE, sizeof(CPUCell));
|
||||||
s->gpu_cells = PyMem_Calloc(self->xnum * SEGMENT_SIZE, sizeof(GPUCell));
|
s->gpu_cells = calloc(self->xnum * SEGMENT_SIZE, sizeof(GPUCell));
|
||||||
s->line_attrs = PyMem_Calloc(SEGMENT_SIZE, sizeof(line_attrs_type));
|
s->line_attrs = calloc(SEGMENT_SIZE, sizeof(line_attrs_type));
|
||||||
if (s->cpu_cells == NULL || s->gpu_cells == NULL || s->line_attrs == NULL) fatal("Out of memory allocating new history buffer segment");
|
if (s->cpu_cells == NULL || s->gpu_cells == NULL || s->line_attrs == NULL) fatal("Out of memory allocating new history buffer segment");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,11 +60,11 @@ static inline PagerHistoryBuf*
|
|||||||
alloc_pagerhist(size_t pagerhist_sz) {
|
alloc_pagerhist(size_t pagerhist_sz) {
|
||||||
PagerHistoryBuf *ph;
|
PagerHistoryBuf *ph;
|
||||||
if (!pagerhist_sz) return NULL;
|
if (!pagerhist_sz) return NULL;
|
||||||
ph = PyMem_Calloc(1, sizeof(PagerHistoryBuf));
|
ph = calloc(1, sizeof(PagerHistoryBuf));
|
||||||
if (!ph) return NULL;
|
if (!ph) return NULL;
|
||||||
size_t sz = MIN(1024u * 1024u, pagerhist_sz);
|
size_t sz = MIN(1024u * 1024u, pagerhist_sz);
|
||||||
ph->ringbuf = ringbuf_new(sz);
|
ph->ringbuf = ringbuf_new(sz);
|
||||||
if (!ph->ringbuf) { PyMem_Free(ph); return NULL; }
|
if (!ph->ringbuf) { free(ph); return NULL; }
|
||||||
ph->maximum_size = pagerhist_sz;
|
ph->maximum_size = pagerhist_sz;
|
||||||
return ph;
|
return ph;
|
||||||
}
|
}
|
||||||
@ -72,7 +72,7 @@ alloc_pagerhist(size_t pagerhist_sz) {
|
|||||||
static inline void
|
static inline void
|
||||||
free_pagerhist(HistoryBuf *self) {
|
free_pagerhist(HistoryBuf *self) {
|
||||||
if (self->pagerhist && self->pagerhist->ringbuf) ringbuf_free((ringbuf_t*)&self->pagerhist->ringbuf);
|
if (self->pagerhist && self->pagerhist->ringbuf) ringbuf_free((ringbuf_t*)&self->pagerhist->ringbuf);
|
||||||
PyMem_Free(self->pagerhist);
|
free(self->pagerhist);
|
||||||
self->pagerhist = NULL;
|
self->pagerhist = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,11 +126,11 @@ static void
|
|||||||
dealloc(HistoryBuf* self) {
|
dealloc(HistoryBuf* self) {
|
||||||
Py_CLEAR(self->line);
|
Py_CLEAR(self->line);
|
||||||
for (size_t i = 0; i < self->num_segments; i++) {
|
for (size_t i = 0; i < self->num_segments; i++) {
|
||||||
PyMem_Free(self->segments[i].cpu_cells);
|
free(self->segments[i].cpu_cells);
|
||||||
PyMem_Free(self->segments[i].gpu_cells);
|
free(self->segments[i].gpu_cells);
|
||||||
PyMem_Free(self->segments[i].line_attrs);
|
free(self->segments[i].line_attrs);
|
||||||
}
|
}
|
||||||
PyMem_Free(self->segments);
|
free(self->segments);
|
||||||
free_pagerhist(self);
|
free_pagerhist(self);
|
||||||
Py_TYPE(self)->tp_free((PyObject*)self);
|
Py_TYPE(self)->tp_free((PyObject*)self);
|
||||||
}
|
}
|
||||||
@ -351,11 +351,11 @@ static void
|
|||||||
pagerhist_rewrap_to(HistoryBuf *self, index_type cells_in_line) {
|
pagerhist_rewrap_to(HistoryBuf *self, index_type cells_in_line) {
|
||||||
PagerHistoryBuf *ph = self->pagerhist;
|
PagerHistoryBuf *ph = self->pagerhist;
|
||||||
if (!ph->ringbuf || !ringbuf_bytes_used(ph->ringbuf)) return;
|
if (!ph->ringbuf || !ringbuf_bytes_used(ph->ringbuf)) return;
|
||||||
PagerHistoryBuf *nph = PyMem_Calloc(sizeof(PagerHistoryBuf), 1);
|
PagerHistoryBuf *nph = calloc(sizeof(PagerHistoryBuf), 1);
|
||||||
if (!nph) return;
|
if (!nph) return;
|
||||||
nph->maximum_size = ph->maximum_size;
|
nph->maximum_size = ph->maximum_size;
|
||||||
nph->ringbuf = ringbuf_new(MIN(ph->maximum_size, ringbuf_capacity(ph->ringbuf) + 4096));
|
nph->ringbuf = ringbuf_new(MIN(ph->maximum_size, ringbuf_capacity(ph->ringbuf) + 4096));
|
||||||
if (!nph->ringbuf) { PyMem_Free(nph); return ; }
|
if (!nph->ringbuf) { free(nph); return ; }
|
||||||
ssize_t ch_width = 0;
|
ssize_t ch_width = 0;
|
||||||
unsigned count;
|
unsigned count;
|
||||||
uint8_t record[8];
|
uint8_t record[8];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user