ogl_beamforming

Ultrasound Beamforming Implemented with OpenGL
git clone anongit@rnpnr.xyz:ogl_beamforming.git
Log | Files | Refs | Feed | Submodules | LICENSE

Commit: 86e6b80a569c9045196a602f749234168ae76ba1
Parent: 1a66af3fd7dbf7f8bd157a841cfba85c13367537
Author: Randy Palamar
Date:   Fri,  2 May 2025 17:27:41 -0600

util: use push_array naming instead of arbitrary "alloc()"

Diffstat:
Mbeamformer.c | 2+-
Mmain_linux.c | 4++--
Mui.c | 8++++----
Mutil.c | 27++++++++++++++-------------
4 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/beamformer.c b/beamformer.c @@ -369,7 +369,7 @@ do_compute_shader(BeamformerCtx *ctx, Arena arena, BeamformComputeFrame *frame, u32 base_index = (u32)(frame - ctx->beamform_frames); u32 to_average = ctx->shared_memory->parameters.output_points.w; u32 frame_count = 0; - u32 *in_textures = alloc(&arena, u32, MAX_BEAMFORMED_SAVED_FRAMES); + u32 *in_textures = push_array(&arena, u32, MAX_BEAMFORMED_SAVED_FRAMES); ComputeFrameIterator cfi = compute_frame_iterator(ctx, 1 + base_index - to_average, to_average); for (BeamformComputeFrame *it = frame_next(&cfi); it; it = frame_next(&cfi)) diff --git a/main_linux.c b/main_linux.c @@ -21,11 +21,11 @@ #include "static.c" -static void +function void dispatch_file_watch_events(OS *os, Arena arena) { FileWatchContext *fwctx = &os->file_watch_context; - u8 *mem = alloc_(&arena, 4096, 64, 1); + u8 *mem = arena_alloc(&arena, 4096, 16, 1); Stream path = stream_alloc(&arena, 256); struct inotify_event *event; diff --git a/ui.c b/ui.c @@ -523,8 +523,8 @@ table_new(Arena *a, i32 initial_capacity, i32 columns, TextAlignment *alignment) Table *result = push_struct(a, Table); da_reserve(a, result, initial_capacity); result->columns = columns; - result->alignment = alloc(a, TextAlignment, columns); - result->widths = alloc(a, f32, columns); + result->alignment = push_array(a, TextAlignment, columns); + result->widths = push_array(a, f32, columns); mem_copy(result->alignment, alignment, sizeof(*alignment) * columns); return result; } @@ -665,7 +665,7 @@ table_push_row(Table *t, Arena *a, TableRowKind kind) { TableRow *result = da_push(a, t); if (kind == TRK_CELLS) { - result->data = alloc(a, TableCell, t->columns); + result->data = push_array(a, TableCell, t->columns); /* NOTE(rnp): do not increase rows for an empty subtable */ t->rows++; } @@ -2480,7 +2480,7 @@ scale_bar_interaction(BeamformerUI *ui, ScaleBar *sb, v2 mouse) add_v2(is->rect.pos, is->rect.size), (v2){{*sb->min_value, *sb->min_value}}, (v2){{*sb->max_value, *sb->max_value}}); - f32 new_coord; + f32 new_coord = F32_INFINITY; switch (sb->direction) { case SB_LATERAL: new_coord = world_mouse.x; break; case SB_AXIAL: new_coord = world_mouse.y; break; diff --git a/util.c b/util.c @@ -53,10 +53,10 @@ arena_pop(Arena *a, iz length) a->beg -= length; } -#define alloc(a, t, n) (t *)alloc_(a, sizeof(t), _Alignof(t), n) -#define push_struct(a, t) (t *)alloc_(a, sizeof(t), _Alignof(t), 1) -static void * -alloc_(Arena *a, iz len, iz align, iz count) +#define push_array(a, t, n) (t *)arena_alloc(a, sizeof(t), _Alignof(t), n) +#define push_struct(a, t) (t *)arena_alloc(a, sizeof(t), _Alignof(t), 1) +function void * +arena_alloc(Arena *a, iz len, iz align, iz count) { /* NOTE: special case 0 arena */ if (a->beg == 0) @@ -101,14 +101,14 @@ da_reserve_(Arena *a, void *data, iz *capacity, iz needed, iz align, iz size) /* NOTE(rnp): handle both 0 initialized DAs and DAs that need to be moved (they started * on the stack or someone allocated something in the middle of the arena during usage) */ if (!data || a->beg != (u8 *)data + cap * size) { - void *copy = alloc_(a, size, align, cap); + void *copy = arena_alloc(a, size, align, cap); if (data) mem_copy(copy, data, cap * size); data = copy; } if (!cap) cap = DA_INITIAL_CAP; while (cap < needed) cap *= 2; - alloc_(a, size, align, cap - *capacity); + arena_alloc(a, size, align, cap - *capacity); *capacity = cap; return data; } @@ -208,7 +208,7 @@ function Stream stream_alloc(Arena *a, iz cap) { Stream result = {.cap = cap}; - result.data = alloc(a, u8, cap); + result.data = push_array(a, u8, cap); return result; } @@ -453,13 +453,14 @@ s8_cut_head(s8 s, iz cut) return result; } -static s8 +function s8 s8_alloc(Arena *a, iz len) { - return (s8){ .data = alloc(a, u8, len), .len = len }; + s8 result = {.data = push_array(a, u8, len), .len = len}; + return result; } -static s8 +function s8 s16_to_s8(Arena *a, s16 in) { s8 result = s8(""); @@ -487,7 +488,7 @@ s8_to_s16(Arena *a, s8 in) s16 result = {0}; if (in.len) { iz required = 2 * in.len + 1; - u16 *data = alloc(a, u16, required); + u16 *data = push_array(a, u16, required); iz length = 0; /* TODO(rnp): utf8_decode */ for (iz i = 0; i < in.len; i++) { @@ -825,10 +826,10 @@ make_hadamard_transpose(Arena *a, u32 dim) arena_capacity(a, i32) >= elements * (1 + multiple_of_12)) { if (!power_of_2) dim /= 12; - result = alloc(a, i32, elements); + result = push_array(a, i32, elements); Arena tmp = *a; - i32 *m = power_of_2 ? result : alloc(&tmp, i32, elements); + i32 *m = power_of_2 ? result : push_array(&tmp, i32, elements); #define IND(i, j) ((i) * dim + (j)) m[0] = 1;