04-11-2012
Retreving the dynamically allocated values from bdb using C
In one of the assignment which i am working on, i am am trying to insert keys and values into BDB by reading the input records from a input file as below.
Here keys i am inserting as character buffer and for values i am dynamically allocating the memory using malloc and then inserting into bdb.
But when i try to retireve the inserted values from BDB i am geting only the latest record for Value.
//KEY
char key[512];
//VALUE
typedef struct
{
char *remValues[10];
}valuestr;
static valuestr vstr;
Dbc *dbcObj;
Dbt dbtKey,dbtValue;
// I am dynamically allocating memory for Value str using malloc example as below.
vstr.remValues[0] = (char *)malloc(50);
while(!feof(inFile))
{
//getting key from input file
strcpy(buf, <value1>); //value1 comes from input file
//getting Value from input file
memset(vstr.remValues[0],0,50);
sprintf(vstr.remValues[0],"%d",<value2>); //value2 comes from input file
...........
...........
//Putting values into BDB
dbtKey.set_data((char*) buf);
dbtKey.set_size(strlen(buf));
dbtValue.set_data((valuestr*)&vstr);
dbtValue.set_size(sizeof(valuestr));
int ret = dbObj.put(0,&dbtKey,&dbtValue,DB_NOOVERWRITE);
}
But when i try to retrive the values from BDB its giving proper values for Key but for Value i am getting only the latest value from input file.
Below is the Key value retreival code.
dbObj.cursor(NULL,&dbcObj,0);
char keys[100];
valuestr *values;
while(dbcObj->get(&dbtKey,&dbtValue,DB_NEXT)==0)
{
memset(keys,0,sizeof(keys));
strncpy(keys,(char *)dbtKey.get_data(),strlen(buf));
values = (valuestr *)dbtValue.get_data();
//printing values and keys on to console
}
Can you please suggest how to resolve this ?
10 More Discussions You Might Find Interesting
1. Solaris
Hi,
How to find out what is the maximum memory allocated to TOMCAT server in SunOS 5.8?
The Tomcat server crashes down during peak times....
Regards (1 Reply)
Discussion started by: baanprog
1 Replies
2. Solaris
Hi,
I have a server that is getting the following alarm a couple times a day:
Mar 25 10:56:54 hostname xntpd: too many recvbufs allocated (30)
Mar 25 10:56:54 hostname xntpd: too many recvbufs allocated (30)
I know this is some sort of NTP related issue but I need to gauge the severity of... (0 Replies)
Discussion started by: BrewDudeBob
0 Replies
3. Solaris
i am working with solaris 9 and my disk usages are
# df -k
Filesystem kbytes used avail capacity Mounted on
/dev/dsk/c0t0d0s0 2148263 1902721 202577 91% /
/proc 0 0 0 0% /proc
mnttab 0 0 0 ... (3 Replies)
Discussion started by: smartgupta
3 Replies
4. Shell Programming and Scripting
Hi all,
I am interning in a unix department and am very new to programming. I am supposed to write a script that counts the amount of filesystems a server has allocated, and the amount free. This is what I was given to start with:
#!/bin/ksh
df -m | grep -v ":"|grep -v Free|grep -v "/proc"|... (6 Replies)
Discussion started by: compan023
6 Replies
5. Programming
I have a pointer to a structure containing an integer pointer:
struct members {
int id;
int *neigh;
};
The number of members N and its neighbors M change as the code runs, so I allocate the memory dynamically:
members *grid = malloc(sizeof(members)*N);
for(i=0;i<N;i++)... (2 Replies)
Discussion started by: brinch
2 Replies
6. Programming
Actually for a process to run it needs text, stack , heap and data segments. All these find a place in the physical memory.
Out of these 4 only heap does exist after the termination of the process that created it. I want to know the exact reason why this happens. Also why the other process need to... (20 Replies)
Discussion started by: karthiktceit
20 Replies
7. Shell Programming and Scripting
I am needing to create a variable(changing) and assign it a value(changing) ... I am using C-Shell..
Example:
foreach account in ($Accountlist)
set account_connect = "$account/$account_pass"
end
I want to make set account_connect to store various values ? $account_connect did not... (3 Replies)
Discussion started by: shafi2all
3 Replies
8. Programming
In one of the assignment which i am working on, i am am trying to insert keys and values into BDB by reading the input records from a input file as below.
Here keys i am inserting as character buffer and for values i am dynamically allocating the memory using malloc and then inserting into bdb.... (1 Reply)
Discussion started by: AmbikaValagonda
1 Replies
9. Shell Programming and Scripting
Hi all,
In ksh, I'm trying to loop through all of my arrays, named array1, array2, array3..., and update the indices. But I'm getting errors and I'm not sure how to fix them. The errors are
./parse.sh: 6+1: not found
The code is:
eval \${array$c}=$(eval \${array$c}+1 )
Any help... (12 Replies)
Discussion started by: nicksantos1
12 Replies
10. UNIX for Dummies Questions & Answers
Hi All,
I have 2 files which i need to merge together based on the column names provided in the file. The first line in both files are header records.
The first file has fixed columns but second file can have subset of the columns from file 1
File 1:
... (6 Replies)
Discussion started by: kushagra
6 Replies
LEARN ABOUT REDHAT
indxbib
INDXBIB(1) General Commands Manual INDXBIB(1)
NAME
indxbib - make inverted index for bibliographic databases
SYNOPSIS
indxbib [ -vw ] [ -cfile ] [ -ddir ] [ -ffile ] [ -hn ] [ -istring ] [ -kn ] [ -ln ] [ -nn ] [ -ofile ] [ -tn ] [ filename... ]
It is possible to have whitespace between a command line option and its parameter.
DESCRIPTION
indxbib makes an inverted index for the bibliographic databases in filename... for use with refer(1), lookbib(1), and lkbib(1). The index
will be named filename.i; the index is written to a temporary file which is then renamed to this. If no filenames are given on the command
line because the -f option has been used, and no -o option is given, the index will be named Ind.i.
Bibliographic databases are divided into records by blank lines. Within a record, each fields starts with a % character at the beginning
of a line. Fields have a one letter name which follows the % character.
The values set by the -c, -n, -l and -t options are stored in the index; when the index is searched, keys will be discarded and truncated
in a manner appropriate to these options; the original keys will be used for verifying that any record found using the index actually con-
tains the keys. This means that a user of an index need not know whether these options were used in the creation of the index, provided
that not all the keys to be searched for would have been discarded during indexing and that the user supplies at least the part of each key
that would have remained after being truncated during indexing. The value set by the -i option is also stored in the index and will be
used in verifying records found using the index.
OPTIONS
-v Print the version number.
-w Index whole files. Each file is a separate record.
-cfile Read the list of common words from file instead of /usr/share/groff/1.18.1/eign.
-ddir Use dir as the pathname of the current working directory to store in the index, instead of the path printed by pwd(1). Usually dir
will be a symbolic link that points to the directory printed by pwd(1).
-ffile Read the files to be indexed from file. If file is -, files will be read from the standard input. The -f option can be given at
most once.
-istring
Don't index the contents of fields whose names are in string. Initially string is XYZ.
-hn Use the first prime greater than or equal to n for the size of the hash table. Larger values of n will usually make searching
faster, but will make the index larger and indxbib use more memory. Initially n is 997.
-kn Use at most n keys per input record. Initially n is 100.
-ln Discard keys that are shorter than n. Initially n is 3.
-nn Discard the n most common words. Initially n is 100.
-obasename
The index should be named basename.i.
-tn Truncate keys to n. Initially n is 6.
FILES
filename.i Index.
Ind.i Default index name.
/usr/share/groff/1.18.1/eign
List of common words.
indxbibXXXXXX Temporary file.
SEE ALSO
refer(1), lkbib(1), lookbib(1)
Groff Version 1.18.1 27 June 2001 INDXBIB(1)