Skip to content

Allocating memory by using built in allocation pool

Taymindis Woon edited this page Sep 27, 2017 · 8 revisions

ngx-c-handler has built in allocation memory management, it will be auto free for every session request.

Sample:

int getProfile(FCGX_Request *request, csif_t * session) {
        int* newId = (char*)csif_alloc(session, sizeof(int));
	flog_info("%s\n", "you reach here with get Request");

	if (session->query_str) {
	    char *userID = (char*) csif_getParam("userId", session->query_str);
	    if (userID) {
                *newId = atoi(userID);
		write_out("This user %s has new id= %d\n", userID, *newId); // the param @userId
            }
	}

	return 1; // return 1 to make finished request.
}

Clone this wiki locally