Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Paiz
Jan 14, 2004
I've been playing around with some game development concepts and have designed a small, crappy engine that I like to tinker around in. Yesterday I decided to start adding in some rudimentary 2D collision detection and I got it working decently with circles last night before going to bed. However, I'm not particularly happy with how the system works and I'm hoping someone can help me out.

I have a base class called hull, which is an abstract class that declares a function call ResolveIntersection, like so:

code:
class Hull
{
public:
	virtual bool ResolveIntersection(Hull* target) = 0;
};
The problem is that in order for an intersection to be calculated it has to know the type of both objects being tested, which kind of defeats the purpose of me even having a base Hull class in the first place. I wanted to see it work so I just threw in an enum HULL_TYPE, which each class will have a unique id from, and a templated Cast() function which will attempt to cast the current object to the type in the template , like so:

code:
class Hull
{
public:
	virtual bool ResolveIntersection(Hull* target) = 0;

	virtual HULL_TYPE GetType() = 0;
	template <class T> T* Cast()
	{
		if(T::ObjectId() == this->GetId()) return (T*)this;
		return NULL;
	}
};
So now all my Hull objects that extend the base Hull class are required to have this ObjectID static function and stuff which I was sort of content with but today I wanted to make a templated line hull so that it could work with ints or floats or doubles or whatever, something like this:

code:
template <class T>
class LineHull : public Hull
{
public:
	//Vector is a template that takes the type of the elements as well as the number of dimensions
	Vector<T, 2> a;
	Vector<T, 2> b;

	bool ResolveIntersection(Hull* target){} //Unimportant

	HULL_TYPE GetType()
	{
		//Ah poo poo what do I return here?!
	}

	static HULL_TYPE ObjectId()
	{
		//Ah poo poo what do I return here?!
	}
};
So I guess my question is: Is there a way I can throw in my own run time type checking method that is compatible with templates or am I going to have to use dynamic_cast? I'm kind of leery of overusing dynamic_cast, but maybe my fears are unsubstantiated?

Also does any of this leave anyone with a sour taste in their mouth, is there a better way I could be setting up this collision poo poo? I was thinking I could avoid all of this run time type checking junk by having a list dedicated to each hull type but then every time I add a new hull type I would have to go back and add functions to all the other hulls for that specific type. I'm hoping to extend this stuff into 3 dimensions later so I'm eventually going to have several different hull types.


Paiz fucked around with this message at 06:52 on Oct 10, 2009

Adbot
ADBOT LOVES YOU

teen bear
Feb 19, 2006

pseudorandom name posted:

The backtrace is a listing of called functions on the stack, in reverse order. The memory map is the layout of memory in your program, which can sometimes be useful for finding problems.

Irrelevant problems in your program (all of which are identified if you build with -Wall like you should)
  • argv should be char **argv or char *argv[], not char *argv
  • you're confusing equality (==) and assignment (=)
  • conc is unused
As to the actual root of the crash, what's open the second time through the loop?

Thanks, I fixed the problem as well as those that you mentioned. Would you mind expanding on conc though? I'm not sure what you mean.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

teen bear posted:

Thanks, I fixed the problem as well as those that you mentioned. Would you mind expanding on conc though? I'm not sure what you mean.

You literally never do anything with the variable conc except declare it.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Paiz posted:

Also does any of this leave anyone with a sour taste in their mouth, is there a better way I could be setting up this collision poo poo? I was thinking I could avoid all of this run time type checking junk by having a list dedicated to each hull type but then every time I add a new hull type I would have to go back and add functions to all the other hulls for that specific type. I'm hoping to extend this stuff into 3 dimensions later so I'm eventually going to have several different hull types.

I can just about guarantee that you don't need multiple hull types in practice. Just write an algorithm that handles convex polygon/-hedron collision and one that does bounding boxes and leave it at that.

Also blah blah something about visitor patterns here. Also also if you have to ask whether RTTI is bad performance-wise for your code, it doesn't matter; if your code can't handle the overhead, you'd know already. (EDIT: boost::variant has a visit function that could probably work for multiple dispatch though I never bothered when i did something similar because it didn't matter in the end).

Oh, finally. Stop parameterizing templates on the type of vector element. That's just silly. You're going to use floats because that's what graphics APIs like. And frankly you almost certainly don't need the extra precision that a couple is going to give you.

Avenging Dentist fucked around with this message at 08:31 on Oct 10, 2009

teen bear
Feb 19, 2006

Avenging Dentist posted:

You literally never do anything with the variable conc except declare it.

Forgot that was there. Thanks for your help on these questions that seem very obvious now

Fat Lou
Jan 21, 2008

Desert Heat? I thought it was Dessert Heat. No wonder it tastes so bad.

So, I have an insertion sort and I need to sort files with 10, 100 etc to 1,000,000 using a number of different sorting algorithms. Anyways, the insertion sort does 100,000 along with the rest of the smaller ones without problem and yet the sort for 1,000,000 does not seem to work. I have even let it sit for over an hour at one point. My merge and quick sort work fine with a 1,000,000. So, any clue on what could be causing it to not work? Here is the code I am using at this moment.

void insertionSort (vector<int>& vector)
{
int j, val;

for(int i= 1; i < vector.size(); i++){
val = vector[i];
j = i - 1;

while((j >= 0) && vector[j] > val){
vector[j + 1] = vector[j];
j = j - 1;
}
vector [j + 1] = val;
}
}

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
How long did the insertion sort of 100,000 take

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
Why not just load the problem up in a debugger and set some breakpoints instead of asking people to do your homework? (An act which is frowned upon.)

Whilst farting I
Apr 25, 2006

What I'm trying to is so incredibly simple that I feel like I'm missing something huge by not getting it - hopefully just syntax with respect to arrays, though.

I'm trying to align two strings in a manner that represents DNA. Given

seq1 = ATCTGAT
seq2 = TGCATA

where each letter-to-letter comparison is given a "score" and matching letters are worth 1 and each mismatch and gap is worth 0, and you're trying to align them in a manner which maximizes the score, it should output

numMatches = 4
matchLocs1 = [2 3 6 7]
matchLocs2 = [1 3 4 5]
seq1aligned = 'AT-CTGAT-'
seq2aligned = '-TGC--ATA'

We're encouraged to use arrays instead of vectors, and vectors should make this easier probably.

I did this to help gauge where the exact matches were:

code:
 TGCATA 
A---1-1
T1---1-
C--1---
T1---1-
G-1----
A---1-1
T1---1-
But it's supposed to be filled out dynamically, with every cell's score being determined in a tree-like manner. So I created M, a 2D int array to try and record those scores

code:
// determines how much to add after comparing seq1[i] and seq2[j]
if (isMatch)
	addedScore = 1;
else
	addedScore = -9;
	
M[i,j] = max(*M(i-1,j) + 0, *M(i,j-1) + 0, *M(i-1,j-1) + addedScore);
(if my explanation isn't clear, something like this: http://www.acm.org/crossroads/xrds13-1/dna.html - figures 2-5)

This is how it's supposed to be scored, and C++ throws a complete shitfit whenever I try to do this. It gives me this error for the last line in the above code:

quote:

incompatible types in assignment of `int' to `int[((unsigned int)((int)len2))]'

The max function is doing nothing more than taking in 3 integers as parameters

code:
int max(int a, int b, int c)
M is defined like so:

code:
int len1 = strlen(seq1);
int len2 = strlen(seq2);
int M[len1][len2];
It has been a while since I've worked with arrays. :nyoron: What do I have to change to set a score at M[i,j]? The way in which it's declared? The way its dimensions are defined? It's probably something little, but it's loving up any chance of moving on to the next step.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
Given int M[len1][len2], "M[i,j]" is not a thing, nor is "M(i,j)". You want "M[i][j]".

Whilst farting I
Apr 25, 2006

Hahaha gently caress, I kept on referencing algorithms which had it written that way so it didn't stand out to me as strange in my program. Thank you :kiddo:

Zakalwe
May 12, 2002

Wanted For:
  • Terrorism
  • Kidnapping
  • Poor Taste
  • Unlawful Carnal Gopher Knowledge

Bacon55555 posted:

So, I have an insertion sort and I need to sort files with 10, 100 etc to 1,000,000 using a number of different sorting algorithms. Anyways, the insertion sort does 100,000 along with the rest of the smaller ones without problem and yet the sort for 1,000,000 does not seem to work. I have even let it sit for over an hour at one point. My merge and quick sort work fine with a 1,000,000. So, any clue on what could be causing it to not work? Here is the code I am using at this moment.

You skipped your computational complexity class, didn't you?

Whilst farting I
Apr 25, 2006

Another stupidly simple thing I'm missing arises: I have a 2D array whose dimensions are dependent on user input, and I need to make a recursive function to retrieve information from that array in a certain way after a bunch of other computations - yet C++ won't let you pass multidimensional arrays through parameters without having an integer for the second parameter. It won't accept integer variables, just integers. I can't make the array a global variable since its parameters won't be known before the user inputs them. What can I do to remedy this?

If this helps, it's this from my last post

code:
int len1 = strlen(seq1);
int len2 = strlen(seq2);
int M[len1][len2];
Sorry if this is even more obvious than the last (if that's possible), today is not my day and my brain's a bit fried.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Zakalwe posted:

You skipped your computational complexity class, didn't you?
If he's writing insertion sort for a class, he's surely a freshman. Indeed, if he's even talking about quadratic sorting algorithms, he's not far enough along in his CS curriculum to have taken a complexity theory class. (though I would have thought his prof would have at least mentioned big-O notation if he's comparing different sorting algorithms)

That said, Bacon55555, fill in these blanks for me:

(107) ** 2 = ______________

(107) * log2(107) = _______________

edit: Here's the punchline:
runtime of insertion sort is O(n^2), mergesort is O(n * lg(n))...

$ bc -l
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
a = ((10^7)^2)
b = ((10^7) * l(10^7))
a
100000000000000
b
161180956.50958319788120000000
a/b
620420.68843321689664469853
l(a/b)/l(10)
5.79268627128627995842



So the insertion sort is 620420 times slower -- almost six orders of magnitude slower -- than a merge or quicksort. This is why nobody ever uses insertion sort in the real world.

Dijkstracula fucked around with this message at 23:18 on Oct 10, 2009

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
That was probably the point of the assignment btw

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Whilst farting I posted:

C++ won't let you pass multidimensional arrays through parameters without having an integer for the second parameter. It won't accept integer variables, just integers.

Yes it will. (No I am not telling you how because that's the wrong solution to your problem.)

Whilst farting I posted:

code:
int len1 = strlen(seq1);
int len2 = strlen(seq2);
int M[len1][len2];

That shouldn't compile in the first place unless you happen to be using some weird amalgamation of C++ and C99. There are lots of solutions to your problem though, such as passing the stride of the matrix into your function, making a matrix class, using boost:mult_array, using an array of pointers-to-arrays (don't do this one).

teen bear
Feb 19, 2006

Is it possible to pad strings with anything other than spaces using printf?

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

teen bear posted:

Is it possible to pad strings with anything other than spaces using printf?

No.

Whilst farting I
Apr 25, 2006

Avenging Dentist posted:

Yes it will. (No I am not telling you how because that's the wrong solution to your problem.)

:nyoron:

quote:

That shouldn't compile in the first place unless you happen to be using some weird amalgamation of C++ and C99.

I've hardcoded seq1 and seq2 into the program, if that helps to explain it - and I'm using this to compile it

http://www.bloodshed.net/devcpp.html

quote:

There are lots of solutions to your problem though, such as passing the stride of the matrix into your function, making a matrix class, using boost:mult_array, using an array of pointers-to-arrays (don't do this one).

What do you mean by passing the stride of the matrix? I can find information about all the other methods, but not this.

UberJumper
May 20, 2007
woop
I have a random question about const correctness.

Lets say i have a class that is a singleton.

code:
class Foo : public Singleton<Foo>
{
    friend class Singleton<Foo>;

public:
    std::wstring GetOrSet(const int id) const;

private:
    Foo();
    ~Foo();
    void LoadStringIntoMap(const int id, const std::wstring &msg);

    std::map<int, std::wstring> strMap;
};
The functions are defined as such

code:
std::wstring Foo::GetOrSet(const int stringId) const
{
    if ( strMap.find(stringId) == strMap.end() )
    {
        Foo::GetInstance()->LoadStringIntoMap(stringId, std::wstring(L"HELLO WORLD222"));
    }
    std::map<int, std::wstring>::const_iterator retStr = strMap.find(stringId);
    return retStr->second;
}

void Foo::LoadStringIntoMap(const int stringId, const std::wstring &msg)
{    
    strMap.insert(std::pair<int, std::wstring>(stringId, msg));
}
If i directly get call LoadStringIntoMap i get an error that it cannot convert this pointer from const Foo to Foo &. Which makes sense. But why does this not happen when i get the singleton instance? And call that function.

Is this just really unsafe?

litghost
May 26, 2004
Builder

UberJumper posted:

I have a random question about const correctness.

Lets say i have a class that is a singleton.

code:
class Foo : public Singleton<Foo>
{
    friend class Singleton<Foo>;

public:
    std::wstring GetOrSet(const int id) const;

private:
    Foo();
    ~Foo();
    void LoadStringIntoMap(const int id, const std::wstring &msg);

    std::map<int, std::wstring> strMap;
};
The functions are defined as such

code:
std::wstring Foo::GetOrSet(const int stringId) const
{
    if ( strMap.find(stringId) == strMap.end() )
    {
        Foo::GetInstance()->LoadStringIntoMap(stringId, std::wstring(L"HELLO WORLD222"));
    }
    std::map<int, std::wstring>::const_iterator retStr = strMap.find(stringId);
    return retStr->second;
}

void Foo::LoadStringIntoMap(const int stringId, const std::wstring &msg)
{    
    strMap.insert(std::pair<int, std::wstring>(stringId, msg));
}
If i directly get call LoadStringIntoMap i get an error that it cannot convert this pointer from const Foo to Foo &. Which makes sense. But why does this not happen when i get the singleton instance? And call that function.

Is this just really unsafe?

The "const" qualifier internal just makes the "this" pointer const. Foo::GetInstance is a static method and does not need the "this" pointer at all, so it is unaffected by the "const" modifier.

UberJumper
May 20, 2007
woop

litghost posted:

The "const" qualifier internal just makes the "this" pointer const. Foo::GetInstance is a static method and does not need the "this" pointer at all, so it is unaffected by the "const" modifier.

Can this lead to problems? Since wont this essentially be unsafe since the compiler thinks that nothing will change in this class during optimization? I am looking at like 45 classes right now and its littered all over with them.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Whilst farting I posted:

I've hardcoded seq1 and seq2 into the program, if that helps to explain it - and I'm using this to compile it

No that does not explain it. You're probably using GCC's weird amalgamation of C99 and C++.

Whilst farting I posted:

http://www.bloodshed.net/devcpp.html

This is the shittiest IDE in the world. Seriously, just use Visual Studio or your favorite editor + gcc. (poo poo, even Eclipse is better.)


Whilst farting I posted:

What do you mean by passing the stride of the matrix? I can find information about all the other methods, but not this.

http://en.wikipedia.org/wiki/Stride_of_an_array

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

UberJumper posted:

Can this lead to problems? Since wont this essentially be unsafe since the compiler thinks that nothing will change in this class during optimization? I am looking at like 45 classes right now and its littered all over with them.

It leads to problems because you've just negated the solitary benefit of a singleton: that you can (relatively) easily change your code to use multiple instances of the singleton when your design changes. What you've done is basically make a global with slightly more awkward syntax. A more important question is: why would you create a const member function that indirectly calls insert on one of its members? That's the opposite of const.

The1ManMoshPit
Apr 17, 2005

UberJumper posted:

Can this lead to problems? Since wont this essentially be unsafe since the compiler thinks that nothing will change in this class during optimization? I am looking at like 45 classes right now and its littered all over with them.

This is a pretty common misconception, but compilers can't optimize around constness in c++ because, as you've demonstrated, they can't really know that you won't modify the object in a const method call. You can obtain a pointer to a member or have one passed into the method, and then there's the existence of const_cast and the mutable keyword...

Zakalwe
May 12, 2002

Wanted For:
  • Terrorism
  • Kidnapping
  • Poor Taste
  • Unlawful Carnal Gopher Knowledge

Avenging Dentist posted:

(poo poo, even Eclipse is better.)

Eclipse/CDT is a decent IDE. The GDB integration is good, the indexer works well for the "intellisense" style and the programmable for matter is very configurable. On top of that you get the benefit of other Eclipse plugins such as Remote System Explorer and Subclipse. For grinding out simple code I use vim, but I turn to Eclipse/CDT for anything serious. I know it has a stigma of "LOL Java", but it really is a decent IDE.

Joe Kickass
Feb 19, 2008

FUCK OFF WE'RE FULL
:siren:ASSIGNMENT HELP:siren:


I've just started learning basic systems programming (forks, pipes etc) and have hit a wall with implementing pipes.

I have two programs 'parent' and 'child'. Parent is launched from the command line, and is supposed to spawn three instances of 'child', and create a loop of pipes between them (parent send messages to child 1, child 1 to child 2 etc).

Currently, the parent will fork three times, and the three forked processes will use the exec system call to run child. Now I have my four programs, but I don't know how to set the pipes up between them, as when I call exec the 'child' program has no knowledge of any of 'parent's variables. Is there a simple way of doing this?

Also, I know this is not strictly C programming, but it's being written in C so I figured this would be as good a place as any to ask.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
Extremely vague assistance: man dup2

Standish
May 21, 2001

Joe Kickass posted:

as when I call exec the 'child' program has no knowledge of any of 'parent's variables. Is there a simple way of doing this?
Children inherit their parents open file descriptors (this is a table in kernel not in userspace so it doesn't get overwritten by exec()), so if you do
code:
// parent 
int fd = open("/etc/passwd"); // "fd" has the value "42"
...
if (!fork()) exec("/some/child/process");
then if the newly exec()ed child process read()s from fd 42 it will get the contents of /etc/passwd.

That on its own doesn't do you much good because, as you point out yourself, how does the child know it's supposed to be reading from fd=42? so the other neat trick is where dup2() comes in:

most unix programs will by default get their input/output from 3 standard file descriptors: stdin(fd=0), stdout(fd=1) and stderr(fd=2). The dup2() system call lets you replace one of these standard file descriptors with your own file descriptor e.g.
code:
// parent
int fd = open("/etc/passwd"); // "fd" has the value "42"
dup2(fd, 0); // fd=42, 0=stdin
read(0, ...); // reading from stdin but data actually comes from /etc/passwd!
...
if (!fork()) exec("/some/child/process");
Now when the child thinks it's reading from stdin(fd=0), its input is actually coming from /etc/passwd, and this is all completely transparent to it.

Pipes are bit more complicated because it's all bidirectional and you can chain them arbitrarily but the same general stuff applies, call dup2() so that the read end of one pipe is duplicated to stdin and the write end of the next pipe in the chain is duplicated to stdout, then fork/exec.

Mata
Dec 23, 2003

Avenging Dentist posted:

This is the shittiest IDE in the world. Seriously, just use Visual Studio or your favorite editor + gcc. (poo poo, even Eclipse is better.)

Why? I really like the package manager. Some options are on by default that I have to turn off before I can use it but it's what I use on windows.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Mata posted:

Why? I really like the package manager. Some options are on by default that I have to turn off before I can use it but it's what I use on windows.

Dev-C++ is like Visual Studio 6 only with less features and a worse interface.

torb main
Jul 28, 2004

SELL SELL SELL
Alright, stupid assignment help, I'm retarded, why the gently caress do I keep segfaulting in the for loop here?

code:
void DualHeap::deleteMin( )
{
	if( isEmpty( ) )
	{
		cerr << "ERROR: Cannot delete min value; empty heap!" << endl;
	}
	else
	{	//Store the index of the min value's location in maxheap
		int maxIndex = 0;
		for(int i = 1; i <= currentSize; i++)
		{
			if(maxHeap[i]->partner == minHeap[1])
			{
				maxIndex = i;
				break;
                        }
		}
		//Replace the deleted value with the last value in the array
		maxHeap[maxIndex] = maxHeap[currentSize];
		minHeap[1] = minHeap[currentSize];
		currentSize--;
		//Restore heap property
		buildHeap();
	}
}
As a note, the arrays maxHeap and minHeap store structs containing an int and a pointer ("partner") to another instance of a same-type struct. This should be first-semester C++ programming stuff, but for some reason I just can't figure out why it's segfaulting.

Adhemar
Jan 21, 2004

Kellner, da ist ein scheussliches Biest in meiner Suppe.

Alman posted:

Alright, stupid assignment help, I'm retarded, why the gently caress do I keep segfaulting in the for loop here?

code:
void DualHeap::deleteMin( )
{
	if( isEmpty( ) )
	{
		cerr << "ERROR: Cannot delete min value; empty heap!" << endl;
	}
	else
	{	//Store the index of the min value's location in maxheap
		int maxIndex = 0;
		for(int i = 1; i <= currentSize; i++)
		{
			if(maxHeap[i]->partner == minHeap[1])
			{
				maxIndex = i;
				break;
                        }
		}
		//Replace the deleted value with the last value in the array
		maxHeap[maxIndex] = maxHeap[currentSize];
		minHeap[1] = minHeap[currentSize];
		currentSize--;
		//Restore heap property
		buildHeap();
	}
}
As a note, the arrays maxHeap and minHeap store structs containing an int and a pointer ("partner") to another instance of a same-type struct. This should be first-semester C++ programming stuff, but for some reason I just can't figure out why it's segfaulting.

We would have to see how you're declaring and initializing maxHeap.

torb main
Jul 28, 2004

SELL SELL SELL

Adhemar posted:

We would have to see how you're declaring and initializing maxHeap.
Thanks for the reply,
code:
class DualHeap
{
	private:
		struct DualPointer
		{
			int key;
			DualPointer* partner;
		};
		DualPointer* maxHeap[100];
		DualPointer* minHeap[100];


};
#endif

Standish
May 21, 2001

Alman posted:

Alright, stupid assignment help, I'm retarded, why the gently caress do I keep segfaulting in the for loop here?
Run your program in a debugger, get a stack trace and dump the local variables? Nobody wants to debug your program by inspection, especially when you're providing it one post at a time.

torb main
Jul 28, 2004

SELL SELL SELL

Standish posted:

Run your program in a debugger, get a stack trace and dump the local variables? Nobody wants to debug your program by inspection, especially when you're providing it one post at a time.

I wasn't sure what kind of information was necessary. I suppose I should have had the foresight to know that you all would have needed to see how the arrays were initialized, but I don't think there's anything else necessary.

Anyway, while running the debugger I found my problem. I was dyslexic and read the wrong function, it was my deleteMax that was throwing the error. And the issue was that I was creating a temporary DualPointer struct without using "new" - I had forgotten to change it in deleteMax when I detected the error earlier on in deleteMin. I appreciate the help, five stars

edit: I have having a related problem, though. If I try to scale up the array size to, say, 25,000, I get a segfault when trying to initialize the arrays. Why is that?

torb main fucked around with this message at 21:23 on Oct 14, 2009

Vinterstum
Jul 30, 2003

Alman posted:

Alright, stupid assignment help, I'm retarded, why the gently caress do I keep segfaulting in the for loop here?




Looking at the code, I get the impression you're allocating your arrays as size+1, and indexing them with [1..size]...

Please tell me I'm wrong.

torb main
Jul 28, 2004

SELL SELL SELL

Vinterstum posted:

Looking at the code, I get the impression you're allocating your arrays as size+1, and indexing them with [1..size]...

Please tell me I'm wrong.
So I'm stupid and forgot one other piece of information. Position 0 is reserved for another part of code, I start the heap structure on position 1.

AbsoluteLlama
Aug 15, 2009

By the power vested in me by random musings in tmt... I proclaim you guilty of crustophilia!

I've never seen any good reason not to use the STL. About the only reason that makes sense is that the compiler doesn't support it correctly, although this shouldn't be a problem with newer systems.

If you don't like the default allocators you can write your own. The STL is pretty drat fast if you have a good optimizing compiler with optimization enabled.

C++0x will also have features further reducing the speed penalties for using the STL.

Honestly, I'd trust using an implementation of the STL & Boost before some EA library.

Adbot
ADBOT LOVES YOU

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
Actually EASTL fills a niche well. STL allocators are an abomination and have a rather poor interface. Note that they discussed the compiler(s) issue a number of times.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply