David, You have some pointer issues going on!
Maybe something like this.... struct db_cache_type { sqlite3 *db; /* database file pointer */ char *key; /* key identifies the database that was opened */ int mode; /* database open mode */ }; struct db_cache_type **db_cache_list; /* list of database connections */ int db_cache_count = 5; /* number of databases in pool */ /* allocate memory for array */ db_cache_list = (struct db_cache_type *)malloc(db_cache_count * sizeof(struct db_cache_type *)); /* aloocate each element pointer */ for (i= 0; i < db_cache_count; i ++) /**** DO NOT type cast malloc ****/ db_cache_list[i] = malloc(sizeof(struct db_cache_type)); sqlite3_open_v2( db_cach_list->key, &db_cache_list[i]->db, flags, NULL); ============== SImpler method, dont use ** on the struct ============= struct db_cache_type { sqlite3 *db; /* database file pointer */ char *key; /* key identifies the database that was opened */ int mode; /* database open mode */ }; struct db_cache_type *db_cache_list; /* list of database connections */ int db_cache_count = 5; /* number of databases in pool */ /* allocate memory for array */ db_cache_list = malloc(db_cache_count * sizeof(struct db_cache_type)); memset(db_cach_list, 0 , sizeof( db_cache_count * sizeof(struct db_cache_type) ); Use is also simpler: sqlite3_open_v2( db_cach_list[i].key, &db_cache_list[i].db, flags, NULL); David Gelt <[EMAIL PROTECTED]> wrote: Hi there, I am having a minor issue when trying to malloc() memory for a list of database connections. I need to keep open a large number of database files and run queries against them. The application is running on Linux and is a synchronuous, single threaded application. In order to keep all these database connections open, I defined an array (simple list) but when I am trying to allocate memory for sqlite3 type I get an error complaining about sizeof(sqlite3). I can't keep defining variables for each database open because there might be too many and I don't know in advance the database name, just its structure. Here is what I am doing: struct db_cache_type { sqlite3 *db; /* database file pointer */ char *key; /* key identifies the database that was opened */ int mode; /* database open mode */ }; struct db_cache_type **db_cache_list; /* list of database connections */ int db_cache_count; /* number of databases in pool */ /* allocate memory for array */ db_cache_list = (struct db_cache_type **)malloc(1 * sizeof(struct db_cache_type *)); /* ______________________________ ERROR ON NEXT LINE at sizeof() ___________________________*/ db_cache_list[i] = (struct sqlite3 *)malloc(db_cache_count * sizeof(struct sqlite3)); db_cache_list[i]->db = db; Any help on how to create an array of sqlite3 database connections would be greatly appreciated. Thanks in advance. David ____________________________________________________________________________________ Get easy, one-click access to your favorites. Make Yahoo! your homepage. http://www.yahoo.com/r/hs