Re: Insert and Retrieve unsigned char sequences using C - Mailing list pgsql-general

From Lew
Subject Re: Insert and Retrieve unsigned char sequences using C
Date
Msg-id i22v9p$6kq$1@news.albasani.net
Whole thread Raw
In response to Insert and Retrieve unsigned char sequences using C  (vinicius_bra <viniciusams@yahoo.com.br>)
List pgsql-general
vinicius_bra wrote:
> I'm developing a system in C and I have a unsigned char pointer that
> represents a struct and I like to store it in a bytea column in postgreSQL.

The pointer does not represent the struct.

> How can I do it?
> Example:
>
> str_t temp;
> unsigned char *ptr;
> ptr = (unsigned char *)&temp;
> store(ptr);
>
> I've already tried some examples, but I didnt have success.
> Could you help me?

You won't have any joy storing the raw pointer value, because when you restore
it it'll most likely be into a different memory map and the structure to which
it used to point will no longer be at the same address, if anywhere.

That's because a C pointer doesn't represent a struct, or anything else other
than an address.  It *points to* the struct.

You need to serialize the struct itself then allocate the pointer when you
deserialize the struct.

--
Lew

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

pgsql-general by date:

Previous
From: Artur Dabrowski
Date:
Subject: Re: Incorrect FTS result with GIN index
Next
From: Lew
Date:
Subject: Re: Insert and Retrieve unsigned char sequences using C