MESSAGE
DATE | 2016-12-21 |
FROM | Ruben Safir
|
SUBJECT | Subject: [Learn] (fwd) Re: Threads and Object Methods
|
From learn-bounces-at-nylxs.com Wed Dec 21 17:20:42 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 B8A2C161318; Wed, 21 Dec 2016 17:20:41 -0500 (EST) X-Original-To: learn-at-nylxs.com Delivered-To: learn-at-nylxs.com Received: from mailbackend.panix.com (mailbackend.panix.com [166.84.1.89]) by mrbrklyn.com (Postfix) with ESMTP id 7C814161313 for ; Wed, 21 Dec 2016 17:20:24 -0500 (EST) Received: from panix3.panix.com (panix3.panix.com [166.84.1.3]) by mailbackend.panix.com (Postfix) with ESMTP id 4A96813F36 for ; Wed, 21 Dec 2016 17:20:23 -0500 (EST) Received: by panix3.panix.com (Postfix, from userid 20529) id 993222EB51; Wed, 21 Dec 2016 17:20:23 -0500 (EST) From: Ruben Safir To: learn-at-nylxs.com User-Agent: tin/2.2.1-20140504 ("Tober an Righ") (UNIX) (NetBSD/6.1.5 (i386)) Message-Id: <20161221222023.993222EB51-at-panix3.panix.com> Date: Wed, 21 Dec 2016 17:20:23 -0500 (EST) Subject: [Learn] (fwd) Re: 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: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: learn-bounces-at-nylxs.com Sender: "Learn"
-- forwarded message -- Path: reader1.panix.com!panix!not-for-mail From: ruben safir Newsgroups: comp.lang.c++ Subject: Re: Threads and Object Methods Date: Sun, 18 Dec 2016 21:15:11 -0500 Organization: PANIX Public Access Internet and UNIX, NYC Lines: 81 Message-ID: References: <6d72eead-14c9-4db9-a9c6-f68c2b27f1a4-at-googlegroups.com> <7pSdnevF5InTn8rFnZ2dnUU78W3NnZ2d-at-brightview.co.uk> NNTP-Posting-Host: www.mrbrklyn.com Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Trace: reader1.panix.com 1482113711 18516 96.57.23.82 (19 Dec 2016 02:15:11 GMT) X-Complaints-To: abuse-at-panix.com NNTP-Posting-Date: Mon, 19 Dec 2016 02:15:11 +0000 (UTC) To: learn-at-nylxs.com User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 In-Reply-To: <7pSdnevF5InTn8rFnZ2dnUU78W3NnZ2d-at-brightview.co.uk> Xref: panix comp.lang.c++:1126136
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 ----- */
-- end of forwarded message -- _______________________________________________ Learn mailing list Learn-at-nylxs.com http://lists.mrbrklyn.com/mailman/listinfo/learn
|
|