If your need is "to determine the size of the buffer at runtime", then the description would be as follows:
If the need is "to dynamically redefine a statically defined buffer" I don't know.
Code:
#include <stdio.h>#include <stdlib.h>#include <pico/stdlib.h>typedef struct { uint16_t vga_virtual_pixel_width; uint16_t vga_virtual_pixel_height;} ScreenModeParams;uint16_t *rgbDataBufferEven;uint16_t *rgbDataBufferOdd;static void init_frame_buffers(ScreenModeParams *params) { rgbDataBufferEven = aligned_alloc(4, params->vga_virtual_pixel_width); rgbDataBufferOdd = aligned_alloc(4, params->vga_virtual_pixel_width); memset(rgbDataBufferEven, 0, params->vga_virtual_pixel_width); memset(rgbDataBufferOdd, 0, params->vga_virtual_pixel_width);}static void free_frame_buffers(void) { free(rgbDataBufferEven); free(rgbDataBufferOdd);}int main(void) { ScreenModeParams params = { .vga_virtual_pixel_width = 320, .vga_virtual_pixel_height = 240, }; init_frame_buffers(¶ms); while (1) ; free_frame_buffers();}
Statistics: Posted by 0yama — Tue Jul 02, 2024 1:35 am