dcsimg
www.webdeveloper.com
Page 1 of 3 123 LastLast
Results 1 to 15 of 43

Thread: sending global vars to a worker?

  1. #1
    Join Date
    Jul 2013
    Posts
    46

    sending global vars to a worker?

    so i know this cant "simply" be done but is there any magic trickery to get around this in any way?
    i have 4000+ lines of code and it all works on instanced code or vars that can too large to deepcopy in any workable time...
    there was a thing i saw somewhere that could move a var to a worker but it would also remove it from where it was and thats no good when i need more than 1 worker to have it

  2. #2
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    5,004
    elaborate on what you mean by sending vars to a "worker" and to do what with and where from?

    You need to give people a slice of code to be going on with and specify what the errors you are getting and what you expect to happen and what is happening.

    You can either upload a text file of the code to this site if the code is too big to post in a thread(s).

    When posting any code, ensure that you wrap code blocks in forum BB Code tags. (see my signature for a clue)
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  3. #3
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    5,004
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  4. #4
    Join Date
    Jul 2013
    Posts
    46
    i am building a 3d game engine with pure javascript and all my own code (heres an earler demo of it)
    its not a simple thing i can just link a small bit of code for lol
    the problem is if you send an obj to it or something it will make a deep copy of it and my code works with a LOT of insistence things that cause inf loops.. so it gives you an error when trying to copy it but there are ways around that... ways that will take me a lot of weeks of recording tho lol
    but the other problem is that some of the vars that are needed can contain a VERY large amount of things so the auto deep copy will take far too long

    there must be some way i can just use a read only pointer or something

  5. #5
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    5,004
    Why do you need a full copy of something? Why not just copy of the bits you need to copy?

    If you can post a copy of what you mean when you talk of copies of things, it might help more.
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  6. #6
    Join Date
    Jul 2013
    Posts
    46
    because you cant copy inf loops aka an obj with instances info of instances info of instances info that leads back to the first one at some point that can and will be assess from any and all levels to get to all of the other info eg
    scene={'objects':{'obj':{'face':{'vert':{}}}}}
    scene.objects['obj']['face']['vert'].face=scene.objects['obj']['face']
    scene.objects['obj']['face'].obj=scene.objects['obj']
    scene.objects['obj'].scene=scene
    (THIS IS JUST A SIMPLE EXAMPLE)

    the next problem is "the bits i need" can contain 100000000s of vars so copying them one at a time and removing all needed instance loops for that one function will take WAY more time than i would save by using workers

    why do i feel like i am just repeating the same things in every reply just wording it differently lol

  7. #7
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    5,004
    They are infinite loops because of what?

    When you talk about objects, especially those in JavaScript, they can't be an infinite loop, they have a size that is determined by the amount of available memory storage.

    The structure of the object you have produced doesn't make sense.

    Code:
    scene={'objects':{'obj':{'face':{'vert':{}}}}}
    scene.objects['obj']['face']['vert'].face=scene.objects['obj']['face']
    scene.objects['obj']['face'].obj=scene.objects['obj']
    scene.objects['obj'].scene=scene
    So you have the object scene containing another object containing another object that you go on to refer to yet another nested object, to top it off, you extend one of the objects and then proceed to push the objects with data that is already part of the object and then the cherry is that you then go to push a full copy of the object into an object in itself.

    As for addressing...
    scene.objects['obj']['face']['vert'].face=scene.objects['obj']['face']
    is the same as
    scene.objects.obj.face.vert.face=scene.objects.obj.face;

    TBH you haven't supplied any code, the example isn't really helping and there is no real reason on earth to need to copy an object into a property of itself.
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  8. #8
    Join Date
    Jul 2013
    Posts
    46
    its a loop because if you try to deep copy it will never finish
    it will work fine until scene.objects['obj'] because to copy that it will need to copy "scene" again and that will copy "scene.objects['obj']" and that will copy "scene" ect and that makes an inf loop

    and i need to do that because scene.objects['obj']['face'] will be stored in a number of other places and i might want to know what scene it is in so all i need to do is face.obj.scene and i have all of the scenes info
    i could just add the scene id but for reasons that take too it would just simply will not work and if you want to know why feel free to watch about 200h of streaming or try to reverse engineer the 5000+ lines of code in the first comment i did (just remove the main.html)
    all the code is there if you want any examples lol basically all of it is needed or it will not work so i cant simply cut out parts

    so once again i ask... do you know how i assess global vars or send them to a worker with out deep copying?

  9. #9
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    5,004
    Why do you need to copy something to send it to a function?

    The method you are using is only going to eat up all your RAM and crash.
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  10. #10
    Join Date
    Dec 2005
    Location
    TX
    Posts
    7,867
    Another question...
    What kind of variable are you trying to represent?
    All strings? Floats, Integers, Arrays, Bytes, Bits?
    A yes/no variable can be represented as 16 bits rather than 16 variables.

    Without providing enough information about your problem,
    you will get nothing but wild guesses in return.

  11. #11
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    5,004
    Quote Originally Posted by JMRKER View Post
    Another question...
    What kind of variable are you trying to represent?
    All strings? Floats, Integers, Arrays, Bytes, Bits?
    A yes/no variable can be represented as 16 bits rather than 16 variables.

    Without providing enough information about your problem,
    you will get nothing but wild guesses in return.
    Thing is he is creating an object

    Code:
    onlyme = {
        one:false,
        two:{name:"somestring",value:"wassomething"},
        three: onlyme
    }
    resulting in a recursive type situation, only in this situation the person is adding a reference to itself within itself.
    The variable would be undefined because it needs to create the variable before it can be available.
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  12. #12
    Join Date
    Jul 2013
    Posts
    46
    ok can you guys repeat what you think i am trying to do so i can find out where my explanation when wrong?
    i have a number of workers (aka functions function other cores) and i need to get the same var to each of them
    the var CAN NOT BE deep coped for reasons such as the amount of info with in it will take too long to copy

    SO my question is... how do i send vars to more than 1 worker with out doing a deep copy?

    what info i send and what i do with it on the other side is irreverent to the question
    if you want example code than look at the entire game engine i coded by hand in the first comment and if you want to know how it works i can link the 200h+ worth of streaming (tho site changes mean you need to pay to see older streams so i dont stream there any more)
    other than that here is where i stream now... feel free to be a follower or what ever and ask me stuff next time i am on

  13. #13
    Join Date
    Aug 2016
    Posts
    113
    Quote Originally Posted by red566 View Post
    its a loop because if you try to deep copy it will never finish
    it will work fine until scene.objects['obj'] because to copy that it will need to copy "scene" again and that will copy "scene.objects['obj']" and that will copy "scene" ect and that makes an inf loop
    you have a circular reference (google it)
    the best solution is
    remove all circular references
    from your code

  14. #14
    Join Date
    Jul 2013
    Posts
    46
    ya that one is still not the big problem ergo why it was never in the first post
    if no one knows can you just say so please
    and if any one knows some one who had worked with workers to do an advanced program that would be nice as well

  15. #15
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    5,004
    Simpler to say,

    No it can't be done...

    Had you not wasted peoples time by being secretive from the outset, then your answer would have arrived sooner and not wasted peoples time.
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles