Skip site navigation (1) Skip section navigation (2)

Problem with memory in C function

From: Diogo Biazus <diogo(at)ikono(dot)com(dot)br>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Problem with memory in C function
Date: 2004-03-26 19:11:44
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-general
Hi folks,

I'm having troubles writing a function that reads a file from fisk and 
return a bytea to database.
Can anyone help me?

I read the entire file into a (char *) and then return it as a bytea:

    fseek(file, 0L, SEEK_END);
    tamanhoArquivo = ftell(file);
    fileContent = palloc(fileSize + 1);
    if(fileContent == NULL )
      elog(ERROR, "Error alocating memory (%i bytes)", fileSize + 1);

    fread(fileContent, fileSize, 1, file);
    PG_RETURN_BYTEA_P((bytea *) fileContent);

And, when I call the funcion in psql, it gives me the following message:
ERROR:  Memory exhausted in AllocSetAlloc(879718306)

Am I doing something wrong?


Diogo Biazus

pgsql-general by date

Next:From: Ron St-PierreDate: 2004-03-26 19:15:30
Subject: Re: [NOVICE] Simple list tables question
Previous:From: Stephan SzaboDate: 2004-03-26 19:04:26
Subject: Re: simple join query runs very slowly

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group