Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-29-2013, 03:06 AM   PM User | #1
Sim
New Coder

 
Join Date: Feb 2009
Posts: 81
Thanks: 1
Thanked 1 Time in 1 Post
Sim is an unknown quantity at this point
Max characters that can be passed threw a Javascript function?

Is there a maximum amount of characters that can be passed threw a javascript function paramater?

ex: display(var1, var2)

say var1 is 2 characters, var2 is 323432432 characters? theoritly speaking.
__________________
Online RPG Creator - Create Your Own Online RPG with no programming knoweldge
Sim is offline   Reply With Quote
Old 01-29-2013, 03:25 AM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,237
Thanks: 59
Thanked 3,998 Times in 3,967 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
That question really threw me. Until I realized you meant "through".

Anyway, I think you asked the wrong question.

Reason: When you pass a string as an argument to a function, you are really only passing a *REFERENCE* to the string. And a *REFERENCE* will surely be represented as a memory pointer of some kind, which means it will likely be a 4-byte or 8-byte pointer (or possible integer, as an index into heap space, but I tend to doubt that implentation would be used).

So the real question you are asking: What is the maximum length of a *STRING* in JavaScript?

The answer is surely both browser dependent and computer dependent.

Computer dependent because of course a string can't be longer than available memory on a given computer.

Browser dependent because it depends on how strings are implemented in a given browser.

Likely the theoretical maximum in most JavaScript implementations is 4 gigabytes or 2 gigacharacters, depending on implementation. Remember that all JavaScript strings are Unicode strings, so that normally means 2 bytes per character. (At least one source--at Google--says, though, that the maximum is about 512MB--or 256 megacharacters--for Chrome.)

But that's all kind of moot: The real limit will almost surely depend on how much space the operating system has allocated for the current browser. After all, the browser has to share memory space with all the other programs executing in your computer. Can the sum of the memory sizes exceed the amount of RAM in your computer? Sure. Heard of "virtual memory", haven't you? But in general the OS will want to try to make sure that all *active* applications are running in real memory.

In practice, if you can manage to make a string too large for a given browser, then your code isn't going to run very well, no matter what. So why are you trying to do this?
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 01-29-2013, 03:52 AM   PM User | #3
Sim
New Coder

 
Join Date: Feb 2009
Posts: 81
Thanks: 1
Thanked 1 Time in 1 Post
Sim is an unknown quantity at this point
My html: I am using smarty templating:

PHP Code:
                        <td>
                            <
strong>Triggers:</strong>
                            <
a href="javascript:;" onclick="AddTrigger('{$template_path}', '{section name=mysec loop=$stats_loop}{$stats_loop[mysec].id}:{$stats_loop[mysec].name}:{/section}','{section name=mysec loop=$items_loop}{$items_loop[mysec].id}:{$items_loop[mysec].name}:{/section}','{section name=mysec loop=$quests_loop}{$quests_loop[mysec].id}:{$quests_loop[mysec].name}:{/section}','{section name=mysec loop=$npcs_loop}{$npcs_loop[mysec].id}:{$npcs_loop[mysec].name}:{/section}','{section name=mysec loop=$images_loop}{$images_loop[mysec].id}:{$images_loop[mysec].name}:{/section}','{section name=mysec loop=$sounds_loop}{$sounds_loop[mysec].id}:{$sounds_loop[mysec].name}:{/section}','{section name=mysec loop=$zones_loop}{$zones_loop[mysec].id}:{$zones_loop[mysec].name}:{/section}');">Add Another Trigger</a>
                        </
td
I am sending my combo box value's through the function. then my javascript. ITS NOT FINISHED YET.

Code:
function AddTrigger(path, stat, item, quest, npc, image, sound, zone) {

  var stats = stat.split(":");
  
  var items = item.split(":");
  
  var quests = quest.split(":");
  
  var npcs = npc.split(":");
  
  var images = image.split(":");
  
  var sounds = sound.split(":");
  
  var zones = zone.split(":");

  var stat_str = '';
  var item_str = '';
  var quest_str = '';
  var npc_str = '';
  var image_str = '';
  var sound_str = '';
  var zone_str = '';
  
  for(var i=0; i<stats.length; i=i+2)
  {
	stat_str = stat_str + '<option value="' + stats[i] + '">' + stats[i + 1] + '</option>';
  }
 
  for(var i=0; i<items.length; i=i+2)
  {
	item_str = item_str + '<option value="' + items[i] + '">' + items[i + 1] + '</option>';
  }
 
  for(var i=0; i<quests.length; i=i+2)
  {
	quest_str = quest_str + '<option value="' + quests[i] + '">' + quests[i + 1] + '</option>';
  }
 
  for(var i=0; i<npcs.length; i=i+2)
  {
	npc_str = npc_str + '<option value="' + npcs[i] + '">' + npcs[i + 1] + '</option>';
  }
 
  for(var i=0; i<images.length; i=i+2)
  {
	image_str = image_str + '<option value="' + images[i] + '">' + images[i + 1] + '</option>';
  }
 
  for(var i=0; i<sounds.length; i=i+2)
  {
	sound_str = sound_str + '<option value="' + sounds[i] + '">' + sounds[i + 1] + '</option>';
  }
 
  for(var i=0; i<zones.length; i=i+2)
  {
	zone_str = zone_str + '<option value="' + zones[i] + '">' + zones[i + 1] + '</option>';
  }
 

  var ni = document.getElementById('div_new_cond');

  var numi = document.getElementById('theValue');

  var num = (document.getElementById('theValue').value -1)+ 2;
 
  numi.value = num;

  var newdiv = document.createElement('div');

  var divIdName = 'my'+num+'Div';

  newdiv.setAttribute('id',divIdName);
 
  newdiv.innerHTML = '<tr><td><img src="' + path + '/default/images/minus.jpeg"> On <select id="selectOption" name="selectOption"><option value="attempt">Attempt</option><option value="if_attempted">If Attempted</option><option value="fail">Fail</option><option value="success">Success</option></select><select name="selectCondition" id="selectCondition" onchange="showCondition()"><optgroup label="Stats"><option value="decrease_stat">Decrease Stat</option><option value="increase_stat">Increase Stat</option><option value="set_stat">Set Stat</option><option value="require_stat">Require Stat</option></optgroup><optgroup label="Tasks"><option value="hide_task">Hide Task</option><option value="show_task">Show Task</option>						<option value="lock_task">Lock Task</option><option value="unlock_task">Unlock Task</option></optgroup><optgroup label="Items"><option value="add_item">Add Item</option><option value="remove_item">Remove Item</option></optgroup><optgroup label="Battling"><option value="attack_player">Attack Player</option><option value="force_battle">Force Battle</option></optgroup><optgroup label="Displays"><option value="display_image">Display Image</option><option value="display_text">Display Text</option><option value="display_sound">Play Sound</option><option value="display_cut_scene">Display Cut Scene</option></optgroup><option value="display_npc">Display NPC</option><option value="move_npc">Move NPC</option><option value="unlock_npc">Unlock NPC</option><option value="lock_npc">Lock NPC</option></optgroup><optgroup label="Quest"><option value="start_quest">Start Quest</option><option value="unlock_quest">Unlock Quest</option><option value="hide_quest">Hide Quest</option><option value="end_quest">End Quest</option><optgroup label="Travel"><option value="teleport">Teleport</option></optgroup></select><div id="valuez"><div id="div_stats"><select id="selectStat" name="selectStat">' + stat_str + '</select>By <input name="textStatMin" type="text" id="textStatMin"> - <input name="textStatMax" type="text" id="textStatMax"></div><div id="div_items"><select id="selectItem" name="selectItem">' + item_str + '</select></div><div id="div_quests"><select id="selectQuest" name="selectQuest">' + quest_str + '</select></div><div id="div_npcs"><select id="selectNPC" name="selectNPC">' + npc_str + '</select></div><div id="div_images"><select id="selectImage" name="selectImage">' + image_str + '</select></div><div id="div_sounds"><select id="selectSound" name="selectSound">' + sound_str + '</select></div><div id="div_zones"><select id="selectZone" name="selectZone">' + zone_str  + '</select></div>  <div id="div_texts"><input name="textText" type="text" id="textText"></div>  </div></td></tr>';

  ni.appendChild(newdiv);

}
__________________
Online RPG Creator - Create Your Own Online RPG with no programming knoweldge
Sim is offline   Reply With Quote
Old 01-29-2013, 04:11 AM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,237
Thanks: 59
Thanked 3,998 Times in 3,967 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
That newdiv.innerHTML is a really bad way to create the contents of that div.

Ugly to use innerHTML with that much crap.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 01-29-2013, 04:29 AM   PM User | #5
Sim
New Coder

 
Join Date: Feb 2009
Posts: 81
Thanks: 1
Thanked 1 Time in 1 Post
Sim is an unknown quantity at this point
What would be a better way to approach this?
__________________
Online RPG Creator - Create Your Own Online RPG with no programming knoweldge
Sim is offline   Reply With Quote
Old 01-29-2013, 04:35 AM   PM User | #6
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,468
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
Quote:
Originally Posted by Old Pedant View Post

Likely the theoretical maximum in most JavaScript implementations is 4 gigabytes or 2 gigacharacters, depending on implementation. Remember that all JavaScript strings are Unicode strings, so that normally means 2 bytes per character. (At least one source--at Google--says, though, that the maximum is about 512MB--or 256 megacharacters--for Chrome.)

But that's all kind of moot: The real limit will almost surely depend on how much space the operating system has allocated for the current browser. After all, the browser has to share memory space with all the other programs executing in your computer.
V8 has a 1gb/instance default pool size, no matter how much RAM the device has. you can use command-line switches to alter that, but you shouldn't be needing that much ram, considering the async storage options available these days.
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Old 01-29-2013, 08:13 AM   PM User | #7
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by Sim View Post
Is there a maximum amount of characters that can be passed threw a javascript function paramater?

ex: display(var1, var2)

say var1 is 2 characters, var2 is 323432432 characters? theoritly speaking.
Why does it matter? Surely no real-world example approaches those limits.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is online now   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:52 AM.


Advertisement
Log in to turn off these ads.