Tricks in C : Pointers

Put your Vanilla code here

Tricks in C : Pointers

Postby hbyte » Wed Jan 31, 2024 6:12 pm

Little tricks to remember that are useful in writing algo's in C/C++
How to create a pointer to an initialised class:
Code: Select all
myclass instance(var1,var2);

myclass* pointer;

pointer = &instance;

Create a list of pointers to class objects
Code: Select all

myclass **pointer;

for(i=0;i<numobj;i++){

pointer[i] = new myclass;

*pointer[i] = myclass(var1,var2);

}

How to initialise a class within a class using a pointer
Code: Select all
class1{

class2* thisclass

class1(){

thisclass = new class2(param1,param2);

}


How to point to another array:
(This works for pointing to an array on your GPU too)
Code: Select all
int *pointer_array,*array;

pointer_array = &array[0]


Create a pointer Array that points to any Array
(This doesnt work for the GPU because it uses a 2d array - not compatable with GPU see next example for GPU.)
Code: Select all
int **pointer_array,*anarray;

anarray = new int[sizeofmyarray];

pointer_array = new int*[howmany_arrays];

pointer_array[0] = &anarray[0];

int myfirst_element = *(pointer_array[0]+1);


If you need a way to get lots of pointers onto the GPU kernel use a struct for example try this:

Code: Select all
typedef struct{
float* pointer1;
float* pointer2;
}myparam;


__global__ void my kernel(myparam mymodel,int* indexforarray){

GPU_1D_KERN_LOOP(index,size){

const int iter = (index /1) % size;

mymodel.pointer1[iter] = something;
mymodel.pointer2[indexforarray+iter] = somethingelse'
}


}



Use a struct of pointers to carry the model parameters onto the kernel rather than list out all the parameters just point to them. Just found this out, although I think I knew from OpenCL. Using structs and pointers for GPU programming is the way forward. Just point to everything you need.

Kickin' as I'm tryin' to sleep
I got the mud beneath my shoes
Rubber band, rubber band
Gun in hand, gun in hand I wanna use

Roamin', roamin', roam
(Get away, gotta get away)
And I think I think too much
(I don't care, yeah but I don't care)
Roamin', roamin', roam
(Get away, gotta get away)
And I think I think too much
hbyte
Site Admin
 
Posts: 80
Joined: Thu Aug 13, 2020 6:11 pm

Re: Jackies Got your back - 'In the Zone'

Postby hbyte » Thu Feb 01, 2024 5:50 pm

-----This Is an E-Brain Snippet Brought to you by JuiCed.extramindcorp.com-----For part one go here


He sat there considering his programming - its clarity was elluding him - due to a hacker's ill recieved attentions.

The hacker was using a proxy and had managed to spy directly on Jackie while he laid out the plans for his parallel markov array. He wanted it ready for a special op he had in mind. But this hacker was making it hard to think real hard. It was thought interception - a classical attack often experienced by shizophrenics and net runners alike.

Luckily Jackie had some help - helpers AI's programmed to facilitate thought and remind him what he was actually doing in the event of a segfault ddos from the hacker. He wasnt immune and wondered why at this ripe old age he had to put up with these constant intrusions.

The op was grand - grander than that. It would mean a permanent base on Jupitors moon Io. A direct link to the rad zone that concealed all that the council would forbid any mere mortal from knowing. The truth about mankind. The unsettiling truth about its real purpose and its altered purpose that now served the needs of the council.

The array. A large unfolding Neural Network thats size was unlimited. Its germination point was a Reversible Cellular Automata called Grandad.

Jackie was working on Grandad's parallel markov array. He was inside the machine on a virtual MPU - massive processing unit that orbited the sun along with several million other users and their AI's.

His implants VR was hardwired, jacked in to the solar-net via a backdoor. It was safer than using the front door - less attention meant less hackers. But this guy could hear him fumbling around with markov routines over the analogue broadcast signals used by this super massive solar array. He could physically be anywhere using any number of proxys situated throughout the sprawling space colony's. Mars, Europa, Uranus even pluto with its authoritarian regime had hackers embedded in the very fabric of this cybernetic universe.

Old skool hackers using analogue signals were the worst and most pernacious form of mind parasite. However Jackie had a solution he was going to ghost himself and spike the ghost to follow the hackers proxys and then nuke his board!! Great. That should work.

It worked all he could hear was someone clearly in agony as he found his system falling apart. Most hackers where hard wired to their decks so some brain damage would be likely for any hacker whose brain had been hardwired to his nuked board.

Turned out the hacker was residing on Pluto behind an AI firewall so deep that the only way in was to use Pluto's very own super AI. A deep underground deep learning neural network with unlimited compute that spanned time and space and owed Jackie a favour.

The super AI enjoyed complete isolation on Pluto and was effectively the most pure AI around.

"Yeah Ive got him you want him nuked or just griefed?" spoke the AI to Jackie over the solar array.

The super AI was just a regular hacker steet trader in his Real Virtual Life RVL. Griefed meant being revealed to the community. Full exposure. Jackie nuked the hackers IP.

Hackers enjoyed an exclusive society which meant getting rid of parasites was a service they provided for each other.

With the only problem removed Jackie began to unfurl his Neural Array. Grandad was being uploaded. After it was done he began to see the Io hardline - it connected thousands of data banks each one containing the neural data for the high council to regenerate in the case of a sudden death. It was the high councils back up data. Every secret member of the high council existed on Io in duplicate while theyre bodys drank the blood shipped from all the humans held on the colonys real or otherwise.

'Thats why theyre so hard to kill', He thought.

"Jackie I warned you what are you doing on Io?", came a voice down the hardline.

'I know that voice' thought Jackie. It was a voice all too familiar. The arch deacon - his original handler when he had been a runner - taking down hackers and those deemed a threat to the council. Those who knew too much. But this had meant Jackie soon learnt the truth. His special skills had always been for hire but he could'nt help feeling bad for those he had killed for the council.

Image
hbyte
Site Admin
 
Posts: 80
Joined: Thu Aug 13, 2020 6:11 pm

Re: Jackie E-Brain

Postby hbyte » Thu Feb 01, 2024 9:20 pm

'Cut the hardline - Ive got a splitter' - splicing you in now - it was Opti his friendly hacker showing up just at the right time and finding the disconnect. Jackie felt himself yanked through time and space it was rather like being choked. He downloaded himself into a duplex clone at station 9 just outside the quarantine zone. He hid there just out of site as the freighter began its automated docking procedure.It carried most of the human body parts destined for beyond the rad zone on Io to where the council held their ritual rights of ressurection - nutrition was paramount. The freighter read cloning depot number 12 - overtly indicating to anyone who did'nt know that it was spares for the clone ships - vessels destined for the outer system colonys where journey time necessitated cloning.

Jackie jumped on board, he carded the locked gate system just before a guard began his nightly inspection of this entry port onto the freighter. His cloned body had most of the physical atributes that Jackie would need to take anyone man or machine down plus a host ofneural overlays and implants which meant he could interface with just about anything electrical. His body came short however in one respect.But hey you can't have it all. 'Cheap low grade clones', murmered Jackie as he felt around downstairs. He sprang another locked door and entered a stairwell that led to the harveting pods. Each body's bio-pod quivered as its contents were slowely drained of blood. The harvesters where well concealed. He could expect surveilance and a more than warm welcome on arrival. The freighter entered orbital speed and began the slingshot manouvre that targeted Io for inertion.The Grav drives kicked in and Jackie was just intime to strap himself in for the journey. No crew meant he had a choice of seatage. 'Nice'

A cleaner bot suddenly appeared around the corner of the gangway he was on. He nearly jumped. No firearm. He would have to fix that. Jackie fell asleep and waited for the landing party. They would be well armed.

"Jackie so pleased you have joined us at last. Its been so long. I hope we can catch up....", It was the deacon again coming through loud and clear on all his trodes. Opti was on the case.

"How long Opti?"

"What how long before he fries your brain, how long before you reach a vegative state from psychosis or...

"You know how long?"

"Its done he is history.It was your new body it took me a while to isolate you from their intranet - that body is prewired to the council.Or was should I say"

"I owe you big time pal."

"Forget it just stay alive. We are counting on you."

"We?"

"Yeah you know the I'm just part of a conglomerate of self aware discarded machine code"

"Oh yeah I remember."

"Ive already tapped your accounts.Don't worry."

Image

Take trip to Myzton?

----- or -----

PayUp Sunshine - Buy a book!!
hbyte
Site Admin
 
Posts: 80
Joined: Thu Aug 13, 2020 6:11 pm


Return to Python and ML

Who is online

Users browsing this forum: No registered users and 46 guests

cron