tiny_malloc error? Urgent please !!

Pages: 1234
Hi all ! I've tried to execute my program several times and i've got this error in many of them:


(gdb) bt
#0 0x93992338 in tiny_malloc_from_free_list ()
#1 0x9398b1cd in szone_malloc ()
#2 0x9398b0d8 in malloc_zone_malloc ()
#3 0x9398b06c in malloc ()
#4 0x90b27598 in operator new ()
#5 0x0000bd48 in __gnu_cxx::new_allocator<unsigned long>::allocate ()
#6 0x0000bd72 in std::_Bvector_base<std::allocator<bool> >::_M_allocate ()
#7 0x0000dbe8 in std::vector<bool, std::allocator<bool> >::_M_insert_aux ()
#8 0x0000dd95 in std::vector<bool, std::allocator<bool> >::push_back ()
#9 0x00003618 in Poblacion::Cruce_uniforme ()
#10 0x000060db in Algoritmo::Algoritmo ()
#11 0x00006c89 in Algoritmo::Algoritmo ()
#12 0x00008f7a in main ()


What does it mean? I'ts urgent because i've got to send my program to a teacher !! thanks to all !! :(
It looks like you've managed to corrupt vector<bool> when calling Poblacion::Cruce_uniforme.

You'll need to post the code of that function.
My code is:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
void Poblacion :: Cruce_uniforme (Individuo & padre1, Individuo & padre2, Individuo & hijo1, Individuo & hijo2)
{
	// Lo primero de todo sera generar dos mascaras aleatorias, una para los
	// parametros booleanos y otro para los reales
	vector<bool> mascara_booleana (0);
	vector<bool> mascara_reales (0);
	
	for (int i = 0; i < padre1.operacion_escalar.size(); i++)
	{
		float b = padre1.Numeros_Aleatorios_Entre_a_y_b (0, 1);
		if (b >= 0.5)
			mascara_booleana.push_back(1);
		else
			mascara_booleana.push_back(0);
	}
	
	for (int i = 0; i < padre1.parametros_reales.size(); i++)
	{
		float b = padre1.Numeros_Aleatorios_Entre_a_y_b (0, 1);
		if (b >= 0.5)
			mascara_reales.push_back(1);
		else
			mascara_reales.push_back(0);
	}
	
	// En este punto se tienen generadas de forma aleatoria unas mascaras que seran
	// distintas para cada cruce.
	
	/* La politica de cruce a uilizar sera la siguiente:
	
			Si 1 en Mascara -> Parametro del padre1 para el hijo1
			Si 0 en Mascara -> Parametro del padre2 para el hijo1
			
			Si 1 en Mascara -> Parametro del padre2 para el hijo2
			Si 0 en Mascara -> Parametro del padre1 para el hijo2
	*/
	
	// Aplicamos el cruce selectivo con la politica anterior para crear el hijo1 y
	// el hijo 2
	for (int i = 0; i < mascara_booleana.size(); i++)
	{
		if (mascara_booleana[i] == 1)
		{
			hijo1.operacion_escalar.push_back (padre1.operacion_escalar[i]);
			hijo2.operacion_escalar.push_back (padre2.operacion_escalar[i]);

		}
		else
		{
			hijo1.operacion_escalar.push_back (padre2.operacion_escalar[i]);
			hijo2.operacion_escalar.push_back (padre1.operacion_escalar[i]);

		}
	}

	for (int i = 0; i < mascara_reales.size(); i++)
	{
		if (mascara_reales[i] == 1)
		{
			hijo1.parametros_reales.push_back (padre1.parametros_reales[i]);
			hijo2.parametros_reales.push_back (padre2.parametros_reales[i]);
		}
		else
		{
			hijo1.parametros_reales.push_back (padre2.parametros_reales[i]);
			hijo2.parametros_reales.push_back (padre1.parametros_reales[i]);
		}
	}
}
Last edited on
It took me a while to figure out where exactly that function was defined. It is part of the Mac OS Kernel's interface. The Mac's C library's malloc() creates and frees data based upon the size of that data.
http://cocoawithlove.com/2010/05/look-at-how-malloc-works-on-mac.html

Based only on this information, I wonder if there is a mismatch between the region being chosen and how much you are allocating. Are you using a std::vector with a lot of data, perhaps? (Do you have a whole lot of population samples?)

I still don't understand what exactly causes the problem, but it seems to be a new one that a lot of Mac developers are hitting... alas.

Sorry I couldn't be of more help. Perhaps if you post your code we can spot some memory allocation irregularities.

[edit] Foo, too slow.
Last edited on
I can't see anything wrong either.

Can you post the code for Individuo::Numeros_Aleatorios_Entre_a_y_b please? I'd like to check if there's something odd in there.
Yes, vectors have a big size.. but not much... More or less 100-200 parameters....

Yes, of course, function is :

1
2
3
4
5
6
7
8
9
10
float Individuo :: Numeros_Aleatorios_Entre_a_y_b (const float & a, const float & b)
{
	return (b-a) * Numeros_Aleatorios_Entre_0_y_1 () + a;
}


float Individuo :: Numeros_Aleatorios_Entre_0_y_1 ()
{
	return (float) rand () / RAND_MAX;
}
All the code looks ok to me.

Going with Duoas's comment above, perhaps you could force the vectors to allocate from a larger pool. You could do so with by inserting the lines in bold:
1
2
3
4
5
6
7
	vector<bool> mascara_booleana (0);
	vector<bool> mascara_reales (0);

	mascara_booleana.reserve(10*1024);
	mascara_reales.reserve(10*1024);

	for (int i = 0; i < padre1.operacion_escalar.size(); i++)

I've done this and the tiny error continues, but now is not for the push_back, now is...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
(gdb) bt
#0  0x93992338 in tiny_malloc_from_free_list ()
#1  0x9398b1cd in szone_malloc ()
#2  0x9398b0d8 in malloc_zone_malloc ()
#3  0x9398b06c in malloc ()
#4  0x90b27598 in operator new ()
#5  0x0000affa in __gnu_cxx::new_allocator<unsigned long>::allocate ()
#6  0x0000b024 in std::_Bvector_base<std::allocator<bool> >::_M_allocate ()
#7  0x0000b03e in std::vector<bool, std::allocator<bool> >::_M_initialize ()
#8  0x0000bca7 in std::vector<bool, std::allocator<bool> >::vector ()
#9  0x0000bd0c in std::vector<bool, std::allocator<bool> >::vector ()
#10 0x000033fe in Poblacion::Cruce_uniforme ()
#11 0x00005f47 in Algoritmo::Algoritmo ()
#12 0x00006af5 in Algoritmo::Algoritmo ()
#13 0x00008de6 in main () 


In other excution the tiny error shows :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
(gdb) bt
#0  0x93992338 in tiny_malloc_from_free_list ()
#1  0x9398b1cd in szone_malloc ()
#2  0x9398b0d8 in malloc_zone_malloc ()
#3  0x9398b06c in malloc ()
#4  0x90b27598 in operator new ()
#5  0x0000affa in __gnu_cxx::new_allocator<unsigned long>::allocate ()
#6  0x0000b024 in std::_Bvector_base<std::allocator<bool> >::_M_allocate ()
#7  0x0000b03e in std::vector<bool, std::allocator<bool> >::_M_initialize ()
#8  0x0000be97 in std::vector<bool, std::allocator<bool> >::operator= ()
#9  0x0000527d in Individuo::Individuo ()
#10 0x000052fe in Individuo::Individuo ()
#11 0x00005cc9 in Algoritmo::Algoritmo ()
#12 0x00006af5 in Algoritmo::Algoritmo ()
#13 0x00008de6 in main () 


But i look to my code and i don'see any error, it seems ok :S I'm going crazy
Last edited on
I think you have some memory corruption somewhere. It's most likely a buffer overrun. However, the code you've posted so far seems perfect.
And there's any posibility to solve it? Or it's a problem from kernel as it was said?
No, the problem lies in your code.

Make sure you aren't writing to memory you don't own, like:

1
2
vector <int> a;
a[ 3 ] = -7;
I've seen all my code and i didn't see nothing like this... :s :(
Patient: Doctor, I'm having gastrointestinal problems.
Doctor: It sounds like something you are eating.
Patient: No, I'm eating good things. Do you think it has anything to do with my stomach?
Doctor: Well, we can take a look, but how about you show me what you are eating, too.
Patient: I've seen all the food I eat and I don't see how it could be a problem.
bwahahahahahaha
mmm point for you haha ... maybe you help me if I show my code, doctor? Will you take a look at the 'food' I've written? hehe :( thanks anyway
It is entirely possible that the error lies in the Mac side of things, but you had better be able to prove it to them.

We really can't help more than to say that you are making some mistake somewhere, probably something odd or obscure that you don't recognize as wrong...
Hi to all again, i've passed the night debugging my program and the only error now is....


1
2
3
4
5
6
7
8
9
10
11
12
13
14
#0  0x93992338 in tiny_malloc_from_free_list ()
#1  0x9398b1cd in szone_malloc ()
#2  0x9398b0d8 in malloc_zone_malloc ()
#3  0x9398b06c in malloc ()
#4  0x90b27598 in operator new ()
#5  0x0000b828 in __gnu_cxx::new_allocator<unsigned long>::allocate (this=0xbffff4d4, __n=1) at ext/new_allocator.h:88
#6  0x0000b852 in std::_Bvector_base<std::allocator<bool> >::_M_allocate (this=0xbffff4d4, __n=6) at stl_bvector.h:389
#7  0x0000b86c in std::vector<bool, std::allocator<bool> >::_M_initialize (this=0xbffff4d4, __n=6) at stl_bvector.h:468
#8  0x0000bafd in std::vector<bool, std::allocator<bool> >::operator= (this=0xbffff4d4, __x=@0x802750) at stl_bvector.h:707
#9  0x000048a9 in Individuo::Individuo (this=0xbffff4d4, rhs=@0x802750) at Individuo.H:171
#10 0x0000492a in Individuo::Individuo (this=0xbffff4d4, rhs=@0x802750) at Individuo.H:174
#11 0x000055f9 in Algoritmo::Algoritmo (this=0xbffff8c4, var=2, ops_L=6, pob=50, inf=-1, sup=1, fich=@0xbffff94c, sel=1, cru=3, mut=1, rep=1, pc=0.899999976, pm=0.100000001, tp=10000, el=1) at Algoritmo.H:287
#12 0x000064cf in Algoritmo::Algoritmo (this=0xbffff8c4, var=2, ops_L=6, pob=50, inf=-1, sup=1, fich=@0xbffff94c, sel=1, cru=3, mut=1, rep=1, pc=0.899999976, pm=0.100000001, tp=10000, el=1) at Algoritmo.H:495
#13 0x000087d1 in main () at main_con_SLP_punto_H.cpp:308 


It seems problem Individuo::Individuo (this=0xbffff4d4, rhs=@0x802750) at Individuo.H and this function is :

1
2
3
4
5
6
7
8
9
10
11
12
Individuo :: Individuo (const Individuo & rhs)
{
	tamanio = rhs.tamanio;
	max_operations_L = rhs.max_operations_L;
	limite_inferior = rhs.limite_inferior;
	limite_superior = rhs.limite_superior;
	fitness = rhs.fitness;
	operacion_escalar.resize(0); -> line 170
	operacion_escalar = rhs.operacion_escalar;
	parametros_reales.resize(0);
	parametros_reales = rhs.parametros_reales; -> line 173
}
Last edited on
Vector assignment is legitimate.

You should note that you're creating a vector, then resizing it to zero (presumably to clear it) then assigning another vector.

You should use the initialiser list in the constructor to construct it from the other vector to begin with.

This appears in the call stack because it happens to be where it crashed, but the cause of the crash is much earlier in the program.
This is beyond my understanding .. : (
Some kind soul who wants to have a look to my project and help me? :(
Pages: 1234