discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Discuss-gnuradio] c++ question


From: Chris Stankevitz
Subject: Re: [Discuss-gnuradio] c++ question
Date: Tue, 21 Oct 2008 10:08:16 -0700
User-agent: Thunderbird 2.0.0.17 (X11/20081013)


Brett L. Trotter wrote:
> I forgot that C++ doesn't support jagged arrays like C# so I created
> this great little jagged array with the 2nd dimension 0 terminated (mask
> of 0 isn't really useful anyway, so I used it like null) so that I could
> figure out how many were in each degree. I've been googling and IRCing
> and trying to figure out if there's a way to initialize a vector of
> vectors as a constant in a class header file or something that would
> hold these constants and coming up short on answers. Do I need to dump
> all my data to a file and read it in? That seems poor for minimizing the
> initialization delay. Is anyone willing to point me in the right direction?


1. You can initialize multidimensional c arrays at compile time:
int a[2][2] = {{1, 2}, {3,4}};

2. If I cared abound speed (like you do), I wouldn't use vector of
vector, rather a single long c-style array.  (I'd use code to make it
appear as it if is a 2-d array eventhough it's 1-d.)  And I'd use
Stream.read and Stream.write to read/write it to disk which will be very
fast.  Using the example above:


int n = Rows * Cols;
int* a = new int[n];

// fill the array here using code

std::ofstream s("array.bin", std::ios::binary);
s.write(reinterpret_cast<const char*>(a), n * sizeof(int));

// subsequent loads will use the binary file:
std::ifstream s("array.bin", std::ios::binary);
s.read(reinterpret_cast<char*>(a), n * sizeof(int));

Chris




reply via email to

[Prev in Thread] Current Thread [Next in Thread]