Re: Insert and Retrieve unsigned char sequences using C

From: Lew <noone(at)lewscanon(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Insert and Retrieve unsigned char sequences using C
Date: 2010-07-20 01:49:32
Message-ID: i22v9p$6kq$1@news.albasani.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Craig Ringer 2010-07-20 05:44:41 "parameterized views" or return-type-inferring SQL functions?
Previous Message vinicius_bra 2010-07-20 00:14:36 Insert and Retrieve unsigned char sequences using C