BitSet - Large N Crashes Program...

Hi!

I have a text file which has N numbers, each of which is represented by 2 bits; as an example, the text file looks as follows:

01 10 00 11 10 10...

This would be 1, 2, 0, 3, 2, 2... The spaces above aren't there, I've just included them for clarity (so what I have in reality is: 011000111010; I can, however, create the file again and change the format if need be). I want to use the bitset container to store these numbers since N is very large (right now, I have N = 205672779) and I would probably have memory issues otherwise.

When I try to declare my bitset, my program compiles correctly and then just freezes:
 
std::bitset<N*2> a;


I am also unaware of how I would assign these values to the bitset in an efficient manner.


The reason I want to do this is I am analyzing genomic data. Each 2-bit number is a base-pair. I want to select subsequences of length L (approx. = 20) and see if they are repeated throughout the rest of the data. Is there a better way of doing this?

Thanks.
Is N a constant? You got to set your bitset to a const value. E.g.

 
const int N = 12;
Last edited on
Yeah, I defined it before, at the top:

 
#define N 205672779 


So I'm pretty confident it has to do with the fact that it's trying to allocate a lot of memory at once. How can I get around this?
Well its 25MB of data. Its big not not HUGE
I suppose trying to create a dynamic bitset that increases in size as you parse the data from the file. Have you tried using malloc?

http://www.cplusplus.com/reference/clibrary/cstdlib/malloc/
Last edited on
That's why I'm puzzled... I tried using malloc and that seems to work, but I run into another problem.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <bitset>
#include <stdio.h>

#define N 205672779

using namespace std;

int main(int argc, char *argv[])
{   
    bitset<2*N>* a;
    a = (bitset<2*N>*) malloc (sizeof(bitset<2*N>));
    
    *a.set(0,1);
    return 0;
}


The problem is at *a.set(0,1).
Well it is a pointer so it should be :

a->set(0,1);
Topic archived. No new replies allowed.