One Char String - performance
Hi-ya all
Two questions, both performance related.
1. What would be the fastest way to produce a one char string, is there anything faster than new String(char + "").
2. What would be the fastest way to get an uppercase from a char, is there anything better than a switch and or set of if/elses, for example some sort of fiddle factor?
thanks
Character.toString(char)
Character.toUpperCase(char)
Similar Messages
-
Making one big String with the same char
I need to generate a String which represents only one char n-times.
Something like:
String str = new String(char Source, int iRepeat)
String str = new String('x', 5);
str = 'xxxxx';
Thanks in advance!public String createString(char c, int n) {
StringBuffer sb = new StringBuffer();
for ( int y=0; y <= n; y++ ) {
sb.append(c);
return sb.toString();
}that should work.
always use string buffers when youre appending text. when you change the value of a STRING object, the jvm actually creates a new string in memory, and just changes the reference to the new string (since each variable you declare as STRING is actually just a reference). this isnt a problem with small strings, but if you create a string thats fairly large, youll notice a huge performance difference. so, just use Strings for storing values, and StringBuffers for string values you plan on changing often. -
Converting more than one char back to a string.
I know this:
String s = Character.toString(letter);
will convert one char back to a string.
What about if you have more than one char, how do you convert them back to a string???When you have more than one char, you probably have them in an array. In that case you can use the String(char[]) constructor.char[] hello = new char[5];
hello[0] = 'h';
hello[1] = 'e';
hello[2] = 'l';
hello[3] = 'l';
hello[4] = 'o';
String salute = new String(hello); -
JTextArea and typing one char at a time!
Hi everyone!
I'm developing an small app. In certain cases, the user may want to edit a little piece of text. For this, I show a new Frame with a JTextArea with the selected text, so the user can edit it...
But I want to control this edition: the user only can type one char at a time, disable selecting text and waiting a short time (250ms) between char and char...
Some ideas? Some suggestion?
Should I use keylistener and wait for the KeyPressed event and wait inside 250 ms?
The reason for the waiting: when the user type a new char (or delete an existing one), I need to do some calculations. And it must be char by char, if the user select text and replace it, or if the user type fast... my program crash.
Thanks in advance!Use a DocumentFilter and add the character yourself one at a time.
Or better perform the calculation there.
http://java.sun.com/docs/books/tutorial/uiswing/components/generaltext.html#filter
Also perform the calculation in the Event Dispatch Thread so it will wait until the calculation is finished before accepting new input. -
Generate unique 10 char string
Hi,
i have to generate a unique 10 char string ( a string with length of 10 ) which has numbers and alphabets with no special characters, is there any code of doing it
Ashishclass UniqueString {
private static final int NUM_CHARS = 10;
private static int[] lastString = new int[NUM_CHARS];
private static final String chars =
"0123456789abcdefghijklmonpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
static String getUnique() {
char[] buf = new char[NUM_CHARS];
carry(lastString, buf.length-1);
for(int i=0;i<buf.length;i++) {
buf[i] = chars.charAt(lastString);
return new String(buf);
private static void carry(int[] ca, int index) {
if(ca[index]==(chars.length()-1)) {
ca[index]=0;
carry(ca,--index);
else ca[index]= ca[index]+1;
public static void main(String[] args) {
for(int i=0;i<10000;i++)
System.out.println(UniqueString.getUnique());
Guarenteed to be unique within one VM instance.
matfud -
How can I get an unsigned char string with nulls from a dll into LabVIEW 6i?
The following ethernet packet data is contained in an unsigned char * string returned from my dll (it's formatted on printing):
Received A 230 Packet On Adapter 0x008F0070
Ethernet Dest: 01.E0.BB.00.00.15 Src: 00.E0.BB.00.DD.CC Type: 0x8868
000000: 01 E0 BB 00 00 15 00 E0 : BB 00 DD CC 88 68 48 41 .............hHA
000010: 00 E0 BB 00 DD CC 80 B3 : 00 00 FF FF 00 02 00 01 ................
000020: 01 00 F0 18 FF 7F 7F FF : FF 7F 7F FF FF 7F 7F FF ................etc., etc.
However, when I read this string into LabVIEW 6i, I only get the following:
01E0 BB
Which is the data before the first NULL or 00 information. I found a "Remove Unprintable Chars.vi" but it
just sees more data before the above string, nothing after, as seen here: 5C30 31E0 BB.
Anybody have any suggestions for how to get the rest of the string? Is there something I can do to further reformat my dll? The dll I'm using is already a wrapper around another dll so I have some flexibility, but the bottom line is, the data I want is in the format of an unsigned char *.Excellent advice, this mostly works so I have some further questions:
I am just reading network traffic off my ethernet card right now, but here is what I get using my C program to test:
000000: 01 E0 BB 00 00 15 00 E0 : BB 00 DD CC 88 68 48 41 .............hHA
000010: 00 E0 BB 00 DD CC 80 B3 : 00 00 FF FF 00 02 00 01 ................
000020: 01 00 38 3C FF 7F 7F 7F : 7F 7F 7F FF FF 7F 7F FF ..8<............
000030: FF 7F 7F FF FF 7F 7F FF : 7F 7F 7F FF FF FF FF FE ................
000040: FE FF FF FF FF 7F 7F 7F : 7F 7E 7E 7F 7F 7E 7E FF .........~~..~~.
000050: 7F 7F 7F 7F FF 7F 7F 7F : 7F 7F 7F FF FF 7F 7E 7F ..............~.
000060: 7F 7F 7E 7F 7F 7E 7F FF : FF 7F FF FF FE FF FF FE ..~..~..........
000070: FF FF FF FF FF 7F 7F FF : FF 7F 7F FF FF FF FF FF ................
000080: FF 7F 7F FF FF 7F 7F FF : FF 7F 7F FF FF 7F 7F FF ................
000090: FF 7F 7F 7F FF 7F 7F 7F : 7F 7F 7F FF FF 7F 7F FF ................
0000A0: FF 7F 7F 7F 7F 7E 7E 7F : 7F 7F FF FF FF FF FF FF .....~~.........
0000B0: FF FF 7F FF FF 7F 7F FF : 7F 7F 7F FF FF 7E 7F FF .............~..
0000C0: FF FF 7F FF FF 7F 7F FF : 7F 7F 7F FF FF 7F 7F FF ................
0000D0: FF 7F 7F FF FF 7F 7F 7F : 7F 7F 7F FF FF FF FF FE ................
0000E0: FE FF FF FF 00 01 : ................
And here is what I get using LabVIEW to call the dll:
0015 00E0 BB00 DDCC 8868 4841 00E0 BB00 DDCC 80B3 0000 FFFF 0002 0001 0100 9600 7F7F 7F7E 7F7F 7F7F 7F7F 7F7F 7F7F 7F00 B405 4300 3300 0000 0000 0000 01E0 BB00 0015 00E0 BB00 DDCC 8868 4841 00E0 BB00 DDCC 80B3 0000 FFFF 0002 0001 0100 9600 7F7F 7F7E 7F7F 7F7F 7F7F 7F7F 7F7F 7F00 F405 1B04 0C04 0000 0000 0000 8000 0000 0000 0000 0800 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
The first thing I notice is that the first 4 bytes are chopped off, and after about 50 bytes, the data is corrupted until the sequence starts to repeat, but this time it starts with the missing 4 bytes and still corrupts after about 55 bytes.
I am expecting the data in LabVIEW to look very similar to the C data because the network packets I am grabbing are pretty consistant, only a couple bytes will vary between them, not the number I am seeing in LabVIEW.
Another side effect I'm seeing is that I can only run my labVIEW code once, if I try running it again it crashes with failures such as:
memory could not be "read"
For reference, I am opening and closing the network adapter inside the read function of my dll, but the pointer seems like it should be intact...
Attachments:
zListAdapters.vi 30 KB
listAdapters.dll 201 KB
Reading.dll 213 KB -
The email I receive from OWA has no line breaks, it is all one long string. This is creating a big problem when I forward the emails received with my BB as they are difficult to read by the recipient. Is there anyway to correct this? I use BIS and access my work email via OWA. I also have a separate personal email set up with no problems with the email I receive or send.
BB Curve 8310 v4.5.0.55
OWA v5.5 SP4
Any help will be appreciated!I'm experiencing the same issue (no line breaks) when pasting rows directly from Excel (2008 & 2011) into a Flex TextArea on a Mac. However, when pasting the exact same data from a Windows Excel spreadsheet, it contains the line breaks.
From Mac: Customer\tPhoneCustomer 1\t555-555-5555Customer 2\t555-555-5556
From Windows: Customer\tPhone\rCustomer 1\t555-555-5555\rCustomer 2\t555-555-5556\r
This appears to be a bug in a flash.display class as pasting the data from Excel to a text editor and then copying/pasting into the same Flex TextArea preserves the original line breaks.
Has anyone figured out a work around? -
Revision: 20754
Revision: 20754
Author: [email protected]
Date: 2011-03-10 03:36:05 -0800 (Thu, 10 Mar 2011)
Log Message:
My latest EndpointPushNotifier change changed the style of the code quite a bit (sorry for that, it was my IDE settings getting in the loop here) I only changed one char line 389.
Modified Paths:
blazeds/trunk/modules/core/src/flex/messaging/client/EndpointPushNotifier.javaI seem to have fixed it by putting <div class="clearfloat"></div> after the navigation bar?
-
How to replace one char with two chars in email address policy?
I very much like to replace the 'ß' char in the surname with 'sz'. However, applying filter '%rßsz%[email protected]' on 'Preußig' leaves me with '[email protected]'.
So, how do I replace one char with two chars in email address policy?As far as I know, your only solution is to manually create such addresses instead of using e-mail address policy.
Ed Crowley MVP "There are seldom good technological solutions to behavioral problems." -
Eliminating ###'s after hex reconversion to char string
This is interesting.
I was originally required to pass a segment to my subroutine. I had to do so using text literals. The symbol is not recognizable by text literals. Therefore, I had to convert the entire string to hex.
I then passed the hex segment to the subroutine, and reconverted it back to char string.
After this I found a ton of unexpected # symbols in my segment. I tried doing a
REPLACE '###' WITH '' INTO CHARSTRING.
, but unsuccessfully. There is not much documentation on hex_to_char conversion, there are 2 FMs on 46, but I cannot get them to work. If anyone knows how to eliminate these unexpected # symbols please let me know.DATA: HEXSTRINGER(6000) TYPE 'X'.
DATA: STRINGER(3000) TYPE 'C'.
FIELD-SYMBOLS: <FSHEX>, <RECONVERT2>.
CALL FUNCTION 'ARCHIVE_GET_NEXT_RECORD'
EXPORTING
ARCHIVE_HANDLE = READ_HANDLE
IMPORTING
RECORD = ARC_BUFFER-SEGMENT
RECORD_STRUCTURE = ARC_BUFFER-RNAME
MOVE ARC_BUFFER-SEGMENT TO SEGSTER.
assign SEGSTER to <fsHEX> type 'X'.
MOVE <fsHEX> to HEXSTRINGER.
APPEND 'REPORT ZSUBR.' TO CODE.
APPEND 'FORM DYN1 USING HEXSTRINGER.' TO CODE.
APPEND 'DATA: SEGSTER2(3000) TYPE ''C''.' TO CODE.
APPEND 'ASSIGN HEXSTRINGER TO <RECONVERT2> TYPE ''C'' .' TO CODE.
APPEND 'MOVE <RECONVERT2> TO SEGSTER2.' TO CODE.
APPEND 'WRITE:/ SEGSTER2.' TO CODE.
APPEND 'ENDFORM.' TO CODE.
I write out Segster2 and compare it to segster.
I've done some variations of this where after I change the char string to hex string I replace 'C' with '7C' into hexstringer and then re-replace it in the subroutine, and then reconvert it to a char string- but actually I don't think that was a necessary step. I believe I can just convert it to hex, and then reconvert it back to hex in the subroutine. -
Revision: 11717
Author: [email protected]
Date: 2009-11-12 11:54:22 -0800 (Thu, 12 Nov 2009)
Log Message:
Bug Fixing Localized SDK - modified one file xercesSchema.properties in xercesImpl_ja.jar - added " to one JA string.
ANT CLEAN MAIN successful
Modified Paths:
flex/sdk/trunk/lib/xercesImpl_ja.jar -
One Search String/Multiple Fields
Hello! What I am trying to do is create a query page for my
users that allows them to enter one search string (var=#string#)
and then click checkboxes that correspond to the field values that
they want to search for the string in (var=#paramSelect#).
Unfortunately I haven't been able to make this work correctly and
was hoping that someone here might be able to help me with this. So
far I have tried the following methods:Dan, I don't think that I am being clear here (or I have
completely misinterpreted what you are trying to say). The problem
that I am trying to overcome right now is having to put each field
into the statement on my results page. Currently the question of
using AND or OR is not a big problem for me. What I DO want to do
is pass the variable #paramSelect# which contains the values from
each of the checked checkboxes from my search page. These values
are the field names in my DB. When a user selects a checkbox, the
value of that checkbox is being passed to my output via
#paramSelect#, so if one checkbox is checked then I get
#paramSelect# equal to field1. If two or more checkboxes are
checked by the user then the value of #paramSelect# becomes a list
of the values (i.e. field1,field3,field5) - this is the dynamic
part that I am having trouble with. With your suggestion what I am
doing is hard-coding each of the field values into my results page:
AND
form.field1 LIKE '%#String#%'
OR form.field2 ....
when what I want to do is have the values passed from the
#paramSelect# variable, separated from the list, and dynamically
inserted into the code. For example:
say that #paramSelect# is passed and contains the values
field1,field3,field5
I would like to write a loop that will separate each value
contained in #paramSelect#
i.e.(field1) (field3) (field5)
and then build the WHERE from these, allowing me to place
something like my previous example:
<cfif FORM.paramSelect IS NOT ""></cfif>
WHERE 1=1
<cfloop list="#FORM.paramSelect#" delimiters=","
index="i">
AND <cfqueryparam cfsqltype="cf_sql_varchar"
value="'#i#'">
LIKE '%#FORM.String#%'
</cfloop>
The idea when I built that statement was that the values
would be separated when the delimiter was reached (,) stored in the
variable #i# and it would loop through the list contained within
#paramSelect#. Unfortunately it doesn't seem to be doing this
because I get 0 records returned even when I search on just 1
field. My main reason for trying to do it this way is the fact that
this DB is going to grow and the available fields are going to
change. If I can store all of this in a variable and pass that to
both the SELECT, WHERE, and a dynamic output table, then it
relieves a lot of headaches and time going through and changing
code in the future. Currently I have the dynamic SELECT and output
tables built, but the WHERE part of the SQL statement is causing
problems.
Thanks again for your input! -
Sun ONE 8.1 performance
Hi,
Do we have any published document on sun one 8.1 performance and scalability ? or something related to performance tuning???
Thanks.......
UmeshThere is a performance tuning document on docs.sun.com at:
http://docs.sun.com/app/docs/doc/819-0084
Is there a specific question you're looking for an answer to?
-Scott -
Bit char string...need help
Hi I am trying to convert a bit char string to something useful. Basically I have an activex tool that allows me acess to a serial port based scale.
I send a weight request command and it sends me this gibberish:
°®°° ìb ÇR
Thank I try to do a tostring() and get this:
\u00b0\u00ae\u00b0\u00b0, on line 1, column 21, is not a valid identifer name.
Hmm.. anyone have to deal with bitchar strings coming from serioal ports or know what i am dealing with here?
Thanks
FrankBasically you need to access the string as a byte array - I think
there's a method getBytes() that you can apply to a string.
Mack -
Sun ONE 6.1 Performance Issues - Sleeping / Hanging
We have been running the Sun family of web servers for many years now, and ran Netscape Enterprise Server 3.6 for a long time.
Several months ago we upgraded to Sun ONE Web Server 6.0 and then 6.1. We have not had any issues until the past few weeks.
Specifically, the web server appears to 'go to sleep' or 'hang' for many seconds - sometimes up to 45 seconds - before processing any requests.
The server will accept the connection immediately but will not return a page. If left alone, the problem will go away, only to return again. A stop and start will also cure the problem.
Some background: 6 web servers run on this same server (Sun E250 2x400 MHz, 1280 MB RAM) - these servers are all relatively lightly loaded. Copper gigabit connection for network.
Primary data is static, with very few cgi-bin scripts and no applets or server-side Java.
All 6 servers have DNS lookups enabled with caching. The server also has a local DNS caching server running (BIND 9) which is used to help performance.
One of the 'public' web servers (external people can access it) is the one showing these performance issues. I've enabled statistics, and it seems during these 'sleepy' periods I see the following in /.perf (which it finally returns): (I am fetching /.perf every minute and timing how long it takes to fetch it, then saving it in a separate file):
webservd pid: 9507
Sun ONE Web Server 6.1 B08/22/2003 12:37 (SunOS DOMESTIC)
Server started Thu Mar 11 00:31:37 2004
Process 9507 started Thu Mar 11 00:31:37 2004
ConnectionQueue:
Current/Peak/Limit Queue Length 98/98/4096
Total Connections Queued 17873
Average Queueing Delay 0.11 milliseconds
ListenSocket group1:
Address http://146.137.96.68:80
Acceptor Threads 1
Default Virtual Server https-www.anl.gov
KeepAliveInfo:
KeepAliveCount 0/256
KeepAliveHits 1414
KeepAliveFlushes 0
KeepAliveRefusals 0
KeepAliveTimeouts 709
KeepAliveTimeout 30 seconds
SessionCreationInfo:
Active Sessions 105
Total Sessions Created 158/256
CacheInfo:
enabled yes
CacheEntries 1024/1024
Hit Ratio 58558/76530 ( 76.52%)
Maximum Age 30
Native pools:
NativePool:
Idle/Peak/Limit 1/1/128
Work Queue Length/Peak/Limit 0/0/0
DNSCacheInfo:
enabled yes
CacheEntries 406/2048
HitRatio 16547/18476 ( 89.56%)
Async DNS disabled
Performance Counters:
Average Total Percent
Total number of requests: 16961
Request processing time: 0.5940 10074.6680
default-bucket (Default bucket)
Number of Requests: 16961 (100.00%)
Number of Invocations: 268684 (100.00%)
Latency: 0.0013 21.2806 ( 0.21%)
Function Processing Time: 0.5927 10053.3877 ( 99.79%)
Total Response Time: 0.5940 10074.6680 (100.00%)
Sessions:
Process Status Function
9507 response flex-log
response flex-log
response shtml_send
response shtml_send
response flex-log
response flex-log
response flex-log
response shtml_send
response flex-log
response flex-log
response flex-log
response shtml_send
response flex-log
response flex-log
response shtml_send
response shtml_send
response shtml_send
response flex-log
response flex-log
response flex-log
response shtml_send
response flex-log
response flex-log
response flex-log
response shtml_send
response shtml_send
response flex-log
response flex-log
response flex-log
response flex-log
response flex-log
response send-file
response shtml_send
response flex-log
response flex-log
response flex-log
response flex-log
response shtml_send
response shtml_send
response flex-log
response flex-log
response shtml_send
response shtml_send
response flex-log
response flex-log
response flex-log
response shtml_send
response flex-log
response shtml_send
response shtml_send
response flex-log
response shtml_send
response flex-log
response shtml_send
response shtml_send
response flex-log
response shtml_send
response flex-log
response flex-log
response shtml_send
response flex-log
response send-cgi
response send-cgi
response shtml_send
response flex-log
response flex-log
response shtml_send
response shtml_send
response shtml_send
response shtml_send
response shtml_send
response shtml-hacktype
response flex-log
response send-cgi
response send-cgi
response send-file
response send-cgi
response flex-log
response shtml_send
response shtml_send
response shtml_send
response flex-log
response shtml_send
response send-file
response flex-log
response send-cgi
response shtml_send
response flex-log
response shtml_send
response send-cgi
response shtml_send
response shtml_send
response flex-log
response flex-log
response send-cgi
response shtml_send
response send-cgi
response flex-log
response shtml_send
response send-file
response send-cgi
response shtml_send
response shtml_send
response flex-log
response service-dump
Why do I have all of these processes queued on the server?
Is DNS causing this? I know Sun ONE 6.x does NOT have asynchronous DNS implemented (although it is an option, it has no effect). Did Netscape Enterprise Server 3.6 has ASync DNS implemented?
We would like to avoid turning off DNS resolution for a number of reasons. However, what really bothers us is that this web server's performance suddenly became a problem while the other 5 servers see FANTASTIC performance and never go to sleep (although some of them are NOT accessible from the general Internet).
Has anyone else seen this?
As a side note, all of these web servers are using a NSAPI plugin that I wrote years ago. It's purpose is access control and automatic forwarding to different pages. It also uses DNS hostnames, but thinking it might be a problem with this web server, I've disabled DNS on the plug-in. It has not helped. Again, this plug-in has worked great for years and is quite straightforward and simple.
Something tells me there is more going on here - thoughts or ideas?
We're getting immensely frustrated here.
In desperation we've made some magnus.conf changes but to no real effect (partially listed below):
DNS on
RqThrottle 256
StackSize 131072
CGIWaitPid on
AsyncDNS off
KeepAliveThreads 2
MaxKeepAliveConnections 256
UseNativePoll 1
RcvBufSize 8192
# default=100
KeepAliveQueryMeanTime 25
# default=100
KeepAliveQueryMaxSleepTime 25
# CGI
MinCgiStubs 10
MaxCgiStubs 50
CGIStubIdleTimeout 45
CGIExpirationTimeout 90
Thanks for any pointers,
--DaveNote that at the moment it seems to be responding normally, but we still have a lot of threads hanging around - very strange...
9507 response flex-log
response flex-log
response flex-log
response flex-log
response flex-log
response shtml_send
response flex-log
response flex-log
response shtml_send
response flex-log
response flex-log
response flex-log
processing flex-log
response shtml_send
response flex-log
response shtml_send
response shtml_send
response shtml_send
response flex-log
response flex-log
response flex-log
response flex-log
response flex-log
response shtml_send
response flex-log
response shtml_send
response flex-log
response shtml_send
response flex-log
response shtml_send
response flex-log
response send-file
response shtml_send
response flex-log
response shtml_send
response send-file
response service-dump
response shtml_send
response shtml_send
response shtml_send
response flex-log
response send-file
response flex-log
response flex-log
response shtml_send
response shtml_send
response flex-log
response flex-log
response shtml_send
response shtml_send
response shtml_send
response flex-log
response shtml_send
response shtml_send
response shtml_send
response shtml_send
response flex-log
response flex-log
response shtml_send
response shtml_send
response shtml_send
response send-file
response flex-log
response flex-log
response flex-log
response flex-log
response flex-log
response flex-log
response flex-log
response shtml_send
response flex-log
response shtml_send
response flex-log
response flex-log
response flex-log
response flex-log
response flex-log
response flex-log
response shtml_send
response flex-log
response shtml_send
response flex-log
response flex-log
response flex-log
response flex-log
response flex-log
response shtml_send
response flex-log
response shtml_send
response shtml_send
response shtml_send
response flex-log
response flex-log
response shtml_send
response flex-log
response flex-log
response flex-log
Maybe you are looking for
-
Hai friends, Requirement is " I need to submit the report in background and program should execute only on every monday of the week. Pl do the needful and clarify with hard coding. Good answers expect good points. Regards, Vamsykrishna.
-
Additional tab at header level in ME21N through BADI ME_GUI_PO_CUST
Hi, I want to have additional tab at header level in ME21n through BADI ME_GUI_PO_CUST. But after all effort I am not getting display of tab. Let me explain what i did till now 1. Appended table EKKO with field 2. Create one function Group -unde
-
HT201364 Unable to install OS X Mavericks
Just bought this computer and am unable to install OS X Mavericks. I get a message telling me that I cannot install it on this computer. I'm at the point of W..T..H? A brand new MacBook Pro 15 and it won't accept Mavericks? Now what? Back to the Appl
-
Connecting to an old Airport Express in Yosemite
Hi, I have a first gen Express and I wanted to connect it to my network. I have Airport Utility 5.6 working though Mahler's launcher: http://coreyjmahler.com/2014/10/16/airport-utility-5-6-1-on-os-x-10-10-yosemite/ My problem is that when I try to co
-
Make VPRS Mandatory at billing, not at Sale Order
Hi I want to make VPRS mandatory at Billling (VF01).... I know that as a std setting. it can be made mandatory from Pricing Procedure in SD.. But that will prevent creation of Sale Order What the user wants it it shud allow creation of sale order, bu