Re: Get object address when creating it in for loop

2014-05-05 Thread Caslav Sabani via Digitalmars-d

Hi Guys,


Thanks so much for your reply. This fixes my problem like Adam D.
Ruppe suggested:

int maxNeurons = 100;
Neuron[] neurons = new Neuron[](maxNeurons);

Neuron n;

for(int i = 0; i  maxNeurons; i++)
{
n = new Neuron();
neurons[] = n;
}

But can you give me a more details so I can understand what is
going on. What is the difference between

Neuron[] neurons = new Neuron[](maxNeurons);

and

Neuron*[] neurons = new Neuron*[](maxNeurons);


As I understand Neuron*[] should create array which elements are
pointers?


Is it possible to instantiate 100 objects in a for loop and get a
address of each object instance and store it in array of pointers?



Thanks


Re: Get object address when creating it in for loop

2014-05-05 Thread Caslav Sabani via Digitalmars-d

Hi Jonathan,



Thanks for your reply. So actually I was getting the pointer of n 
itself.


I understand now what was my problem. The problem was that I did 
not know that array support references of objects, so I thought 
that I must fill it with pointers of objects.


But its great that I do not have to use pointers :)



Thanks a lot.


Create many objects using threads

2014-05-05 Thread Caslav Sabani via Digitalmars-d-learn

Hi,


I have just started to learn D. Its a great language. I am trying 
to achieve the following but I am not sure is it possible or 
should be done at all:


I want to have one array where I will store like 10  objects.

But I want to use 4 threads where each thread will create 25000 
objects and store them in array above mentioned. And all 4 
threads should be working in parallel because I have 4 core 
processor for example. I do not care in which order objects are 
created nor objects should be aware of one another. I just need 
them stored in array.


Can threading help in creating many objects at once?

Note that I am beginner at working with threads so any help is 
welcome :)



Thanks


Re: Create many objects using threads

2014-05-05 Thread Caslav Sabani via Digitalmars-d-learn

Hi Ali,


Thanks for your reply. But I am struggling to understand from 
your example where is the code that creates or spawns new thread.



How do you create new thread and fill array with instantiated 
objects in that thread?




Thanks


Re: Create many objects using threads

2014-05-05 Thread Caslav Sabani via Digitalmars-d-learn

Hi all,


Thanks for your reply. So basically using threads in D for 
creating multiple instances of class is actually slower.



But what does exactly means that Garbage Collector blocks? What 
does it blocks and in which way?




Thanks