Header file:
graphics.h
Synopsis:
void far * far _graphgetmem(unsigned size);
void far _graphfreemem(void far *ptr, unsigned size);
Description:
User hooks which can be used for memory allocation and deallocation.
_graphgetmem & graphfreemem functions in c graphics
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <alloc.h>
/* called by the graphics kernel to allocate memory */
void far * far _graphgetmem(unsigned sz) {
printf("Inside _graphgetmem to allocate %d bytes\n", sz);
delay(500);
/* allocate memory from far heap */
return farmalloc(size);
}
/* called by the graphics kernel to free memory */
void far _graphfreemem(void far *ptr, unsigned sz) {
printf("Inside _graphfreemem to deallocate %d bytes\n", sz);
delay(500);
/* free ptr from far heap */
farfree(ptr);
}
int main(void) {
/* request auto detection */
int graphicDriver = DETECT;
int graphicMode, err;
/* initialize graphics and local variables */
initgraph(&graphicDriver, &graphicMode,
"C:/TURBOC3/BGI");
/* read result of initialization */
err = graphresult();
if (err != grOk) {
/* an error occurred */
printf("Graphic Error: %s\n",
grapherrormsg(err));
getch();
return 0;
}
/* display a message */
settextjustify(CENTER_TEXT, CENTER_TEXT);
outtextxy(getmaxx() / 2, getmaxy() / 2, "Closing graphics");
/* clean up */
closegraph();
return 0;
}
Output: (_graphgetmem & _graphfreemem built-in functions in c graphics.h)
No comments:
Post a Comment