MESSAGE
DATE | 2016-12-18 |
FROM | ruben safir
|
SUBJECT | Re: [Learn] Threads and Object Methods
|
From learn-bounces-at-nylxs.com Sun Dec 18 21:15:14 2016 Return-Path: X-Original-To: archive-at-mrbrklyn.com Delivered-To: archive-at-mrbrklyn.com Received: from www.mrbrklyn.com (www.mrbrklyn.com [96.57.23.82]) by mrbrklyn.com (Postfix) with ESMTP id E6640161312; Sun, 18 Dec 2016 21:15:13 -0500 (EST) X-Original-To: learn-at-nylxs.com Delivered-To: learn-at-nylxs.com Received: from [10.0.0.62] (flatbush.mrbrklyn.com [10.0.0.62]) by mrbrklyn.com (Postfix) with ESMTP id DBE5F160E77 for ; Sun, 18 Dec 2016 21:15:11 -0500 (EST) Newsgroups: comp.lang.c++ References: <6d72eead-14c9-4db9-a9c6-f68c2b27f1a4-at-googlegroups.com> <7pSdnevF5InTn8rFnZ2dnUU78W3NnZ2d-at-brightview.co.uk> From: ruben safir To: learn-at-nylxs.com Message-ID: Date: Sun, 18 Dec 2016 21:15:11 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: <7pSdnevF5InTn8rFnZ2dnUU78W3NnZ2d-at-brightview.co.uk> Subject: Re: [Learn] Threads and Object Methods X-BeenThere: learn-at-nylxs.com X-Mailman-Version: 2.1.17 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: learn-bounces-at-nylxs.com Sender: "Learn"
On 12/18/2016 04:40 PM, Vir Campestris wrote: > You're missing the second parameter to the function. Perhaps if he'd > written > > Reader foo; > std::thread paint(&reader::read_chunk, &foo); > > it would have made more sense to you. You can pass args to the function, > which may include a pointer to an object of the type. I prefer to pass a > pointer to a static member function for the first parameter which takes > a pointer to an object of the class and invokes a corresponding > non-static member. > > Andy
Not really. There are data members of the object that are dynamically altered and stored in the private encapsulation of the object which a a method handles inside the thread. read_chunk is a member of the Image class and it is assigned indexes within a block of memory, and a chunk of raw data. It interprets the block of memory and writes to the block of memory which is private to an instance of Image. The idea was to create a number of threads that write to the block, each in its assigned area, simultaneously in parallel.
read_chunk looks like this
void Image::read_chunk ( ) { CHUNKY * new_chunk = set_chunk();//the chunk construction call is within std::cout << "Type " << new_chunk->type() << std::endl; std::cout << "Length " << new_chunk->length() << std::endl; std::cout << "CRC " << new_chunk->cr() << std::endl; if(new_chunk->type() == "IHDR") { std::cout << "we have a header chunk " << std::endl; IHDR * head = new IHDR; unsigned char * cur = new_chunk->data(); //NOTE:: cur is now point at the new heap for in CHNUNK and not the index for the file head->width = ntohl( *(reinterpret_cast(cur ) ) ); cur += 4; head->height = ntohl( *(reinterpret_cast( cur ) ) ); cur += 4; head->depth = *( reinterpret_cast( cur ) ); cur++; head->color_type = *( reinterpret_cast( cur ) ); cur++; head->compress = *( reinterpret_cast( cur ) ); cur++; head->filter = *( reinterpret_cast( cur ) ); cur++; head->interlace = *( reinterpret_cast( cur ) ); cur++; canvas_size = static_cast(head->height) * static_cast(head->width) * blank_canvas_psize(*head); canvas = new unsigned char[ canvas_size ]; std::cout << "Canvas made: " << static_cast(head->height) * static_cast(head->width) * blank_canvas_psize(*head) << " bytes" << std::endl; //char tmp; //std::cin >> tmp; }
if(new_chunk->type() == "IDAT") { //confusion here. Do we want to create a new data array on the heap to pass through to the images for placement on canvas? //No. Not needed. Use the CHUNKY object instead. It already has the data array. Have the chunky obj schedule itself for //copy to the canvas set_canvas(*new_chunk); //SET MUTEX LOCK and assign canvas index to a CHUNKY object } if(new_chunk->type() == "IEND") { std::cout << "we have a IEND chunk " << std::endl; //set_index(get_index() + 12 + new_chunk->length() ) ; return; } std::thread ctch = getNext(); //calls this method in recursion ctch.join(); //I want this to be detached //read_chunk(); return ; } /* ----- end of method Image::read_chunk ----- */
_______________________________________________ Learn mailing list Learn-at-nylxs.com http://lists.mrbrklyn.com/mailman/listinfo/learn
|
|